From d0c07823c953c78627cdb45592c7e65d8f358867 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Thu, 17 Aug 2023 12:08:18 -0400 Subject: [PATCH 1/2] utils: suppress errno when file is empty but readable. Suppress a false error log when flb_utils_read_file reads empty files. Signed-off-by: Phillip Whelan --- src/flb_utils.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/flb_utils.c b/src/flb_utils.c index ac876175a56..d0864d4d9f1 100644 --- a/src/flb_utils.c +++ b/src/flb_utils.c @@ -1303,7 +1303,9 @@ int flb_utils_read_file(char *path, char **out_buf, size_t *out_size) bytes = fread(buf, st.st_size, 1, fp); if (bytes < 1) { - flb_errno(); + if (bytes < 0) { + flb_errno(); + } flb_free(buf); fclose(fp); return -1; From 37634dfa3e6dcbef69ec0ee13225c5d766a0b364 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 29 Aug 2023 11:16:09 -0400 Subject: [PATCH 2/2] utils: use ferror and not math to check file handler for error. Signed-off-by: Phillip Whelan --- src/flb_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flb_utils.c b/src/flb_utils.c index d0864d4d9f1..c2b2f58a6f7 100644 --- a/src/flb_utils.c +++ b/src/flb_utils.c @@ -1303,7 +1303,7 @@ int flb_utils_read_file(char *path, char **out_buf, size_t *out_size) bytes = fread(buf, st.st_size, 1, fp); if (bytes < 1) { - if (bytes < 0) { + if (ferror(fp)) { flb_errno(); } flb_free(buf);