Commit 6ae873b9 authored by Andrii Simiklit's avatar Andrii Simiklit Committed by Eric Engestrom

intel/tools: make sure the binary file is properly read

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 <> )

v3: Zero size file check placed before fread with exit()
       ( Eric Engestrom <> )

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 <> )
Signed-off-by: 's avatarAndrii Simiklit <>
Reviewed-by: Lionel Landwerlin's avatarLionel Landwerlin <>
Reviewed-by: Eric Engestrom's avatarEric Engestrom <>
parent d7b99ab9
......@@ -47,17 +47,23 @@ i965_disasm_get_file_size(FILE *fp)
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);
if (!size) {
return NULL;
return assembly;
......@@ -167,7 +173,11 @@ int main(int argc, char *argv[])
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");
fprintf(stderr, "Input file is empty\n");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment