Skip to content

Commit 2e669a1

Browse files
committed
mosquitto_read_file: Set return values early
1 parent 6274730 commit 2e669a1

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

libcommon/file_common.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ int mosquitto_read_file(const char *file, bool restrict_read, char **buf, size_t
432432
size_t buflen_i;
433433

434434
*buf = NULL;
435+
if(buflen){
436+
*buflen = 0;
437+
}
435438
fptr = mosquitto_fopen(file, "rt", restrict_read);
436439
if(fptr == NULL){
437440
return MOSQ_ERR_ERRNO;
@@ -444,10 +447,6 @@ int mosquitto_read_file(const char *file, bool restrict_read, char **buf, size_t
444447
fclose(fptr);
445448
return MOSQ_ERR_ERRNO;
446449
}else if(l == 0){
447-
*buf = NULL;
448-
if(buflen){
449-
*buflen = 0;
450-
}
451450
fclose(fptr);
452451
return MOSQ_ERR_SUCCESS;
453452
}

0 commit comments

Comments
 (0)