fuzzing: Fix minor Coverity warning about return values

ftell() could theoretically fail; handle that.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1430667
This commit is contained in:
Philip Withnall 2020-11-13 14:12:18 +00:00
parent a8bc604988
commit 895da99694

View File

@ -10,6 +10,7 @@ int
main (int argc, char **argv) main (int argc, char **argv)
{ {
FILE *f; FILE *f;
long tell_result;
size_t n_read, len; size_t n_read, len;
unsigned char *buf; unsigned char *buf;
@ -19,7 +20,9 @@ main (int argc, char **argv)
f = fopen (argv[1], "r"); f = fopen (argv[1], "r");
assert (f); assert (f);
fseek (f, 0, SEEK_END); fseek (f, 0, SEEK_END);
len = ftell (f); tell_result = ftell (f);
assert (tell_result >= 0);
len = (size_t) tell_result;
fseek (f, 0, SEEK_SET); fseek (f, 0, SEEK_SET);
buf = (unsigned char*) malloc (len); buf = (unsigned char*) malloc (len);
n_read = fread (buf, 1, len, f); n_read = fread (buf, 1, len, f);