1. tools/i965_disasm.c:58:4: warning:
ignoring return value of ‘fread’,
declared with attribute warn_unused_result
fread(assembly, *end, 1, fp);
v2: Fixed incorrect return value check.
( Eric Engestrom <eric.engestrom@intel.com> )
v3: Zero size file check placed before fread with exit()
( Eric Engestrom <eric.engestrom@intel.com> )
v4: - Title is changed.
- The 'size' variable was moved to top of a function scope.
- The assertion was replaced by the proper error handling.
- The error message on a caller side was fixed.
( Eric Engestrom <eric.engestrom@intel.com> )
Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
static void *
i965_disasm_read_binary(FILE *fp, size_t *end)
{
+ size_t size;
void *assembly;
*end = i965_disasm_get_file_size(fp);
+ if (!*end)
+ return NULL;
assembly = malloc(*end + 1);
if (assembly == NULL)
return NULL;
- fread(assembly, *end, 1, fp);
+ size = fread(assembly, *end, 1, fp);
fclose(fp);
-
+ if (!size) {
+ free(assembly);
+ return NULL;
+ }
return assembly;
}
assembly = i965_disasm_read_binary(fp, &end);
if (!assembly) {
- fprintf(stderr, "Unable to allocate buffer to read binary file\n");
+ if (end)
+ fprintf(stderr, "Unable to allocate buffer to read binary file\n");
+ else
+ fprintf(stderr, "Input file is empty\n");
+
exit(EXIT_FAILURE);
}