Skip to content

Commit 2b26784

Browse files
phirsovthiagomacieira
authored andcommitted
Typo fixed in stdlib fread(...) usage
fread(...) function returns the number of items read so far, not number of bytes, ergo, reading one st.st_size sized item produces 1 on success and 0 on failure. Possibly fixing issue #77 Signed-off-by: phirsov <[email protected]>
1 parent 37d4ba4 commit 2b26784

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

examples/simplereader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static uint8_t *readfile(const char *fname, size_t *size)
1515
if (fstat(fileno(f), &st) == -1)
1616
return NULL;
1717
uint8_t *buf = malloc(st.st_size);
18-
*size = fread(buf, st.st_size, 1, f);
18+
*size = fread(buf, st.st_size, 1, f) == 1 ? st.st_size : 0;
1919
fclose(f);
2020
return buf;
2121
}

0 commit comments

Comments
 (0)