From 2e669a1c32171f9aeb2a602e7adeba62d75c2f1a Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 29 Oct 2025 10:45:04 +0000 Subject: [PATCH] mosquitto_read_file: Set return values early --- libcommon/file_common.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libcommon/file_common.c b/libcommon/file_common.c index 5bfa2b87..1ba4d8b3 100644 --- a/libcommon/file_common.c +++ b/libcommon/file_common.c @@ -432,6 +432,9 @@ int mosquitto_read_file(const char *file, bool restrict_read, char **buf, size_t size_t buflen_i; *buf = NULL; + if(buflen){ + *buflen = 0; + } fptr = mosquitto_fopen(file, "rt", restrict_read); if(fptr == NULL){ return MOSQ_ERR_ERRNO; @@ -444,10 +447,6 @@ int mosquitto_read_file(const char *file, bool restrict_read, char **buf, size_t fclose(fptr); return MOSQ_ERR_ERRNO; }else if(l == 0){ - *buf = NULL; - if(buflen){ - *buflen = 0; - } fclose(fptr); return MOSQ_ERR_SUCCESS; }