file_utils: Fix error detection in get_file_size function

The fseek function returns -1 to signal an error. Return value was assigned
to a variable without a sign, so the error could not be detected.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
This commit is contained in:
Adrian Warecki 2023-03-07 13:52:42 +01:00 committed by pjdobrowolski
parent 4aacac3460
commit 125745bcad
1 changed files with 4 additions and 3 deletions

View File

@ -44,7 +44,7 @@ int create_file_name(char *new_name, const size_t name_size, const char *templat
int get_file_size(FILE *f, const char* filename, size_t *size)
{
int ret;
long pos;
assert(size);
/* get file size */
@ -52,13 +52,14 @@ int get_file_size(FILE *f, const char* filename, size_t *size)
if (ret)
return file_error("unable to seek eof", filename);
*size = ftell(f);
if (*size < 0)
pos = ftell(f);
if (pos < 0)
return file_error("unable to get file size", filename);
ret = fseek(f, 0, SEEK_SET);
if (ret)
return file_error("unable to seek set", filename);
*size = pos;
return 0;
}