<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<br><br>Could you please take a look on this v4 if it is possible?<br><br>Thanks,<br>Andrii.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 14, 2018 at 6:30 PM <<a href="mailto:asimiklit.work@gmail.com">asimiklit.work@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Andrii Simiklit <<a href="mailto:andrii.simiklit@globallogic.com" target="_blank">andrii.simiklit@globallogic.com</a>><br>
<br>
1. tools/i965_disasm.c:58:4: warning:<br>
ignoring return value of ‘fread’,<br>
declared with attribute warn_unused_result<br>
fread(assembly, *end, 1, fp);<br>
<br>
v2: Fixed incorrect return value check.<br>
( Eric Engestrom <<a href="mailto:eric.engestrom@intel.com" target="_blank">eric.engestrom@intel.com</a>> )<br>
<br>
v3: Zero size file check placed before fread with exit()<br>
( Eric Engestrom <<a href="mailto:eric.engestrom@intel.com" target="_blank">eric.engestrom@intel.com</a>> )<br>
<br>
v4: - Title is changed.<br>
- The 'size' variable was moved to top of a function scope.<br>
- The assertion was replaced by the proper error handling.<br>
- The error message on a caller side was fixed.<br>
( Eric Engestrom <<a href="mailto:eric.engestrom@intel.com" target="_blank">eric.engestrom@intel.com</a>> )<br>
<br>
Signed-off-by: Andrii Simiklit <<a href="mailto:andrii.simiklit@globallogic.com" target="_blank">andrii.simiklit@globallogic.com</a>><br>
---<br>
src/intel/tools/i965_disasm.c | 16 +++++++++++++---<br>
1 file changed, 13 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/src/intel/tools/i965_disasm.c b/src/intel/tools/i965_disasm.c<br>
index 73a6760fc1..0efbdab706 100644<br>
--- a/src/intel/tools/i965_disasm.c<br>
+++ b/src/intel/tools/i965_disasm.c<br>
@@ -47,17 +47,23 @@ i965_disasm_get_file_size(FILE *fp)<br>
static void *<br>
i965_disasm_read_binary(FILE *fp, size_t *end)<br>
{<br>
+ size_t size;<br>
void *assembly;<br>
<br>
*end = i965_disasm_get_file_size(fp);<br>
+ if (!*end)<br>
+ return NULL;<br>
<br>
assembly = malloc(*end + 1);<br>
if (assembly == NULL)<br>
return NULL;<br>
<br>
- fread(assembly, *end, 1, fp);<br>
+ size = fread(assembly, *end, 1, fp);<br>
fclose(fp);<br>
-<br>
+ if (!size) {<br>
+ free(assembly);<br>
+ return NULL;<br>
+ }<br>
return assembly;<br>
}<br>
<br>
@@ -167,7 +173,11 @@ int main(int argc, char *argv[])<br>
<br>
assembly = i965_disasm_read_binary(fp, &end);<br>
if (!assembly) {<br>
- fprintf(stderr, "Unable to allocate buffer to read binary file\n");<br>
+ if(end)<br>
+ fprintf(stderr, "Unable to allocate buffer to read binary file\n");<br>
+ else<br>
+ fprintf(stderr, "Input file is empty\n");<br>
+</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
exit(EXIT_FAILURE);<br>
}<br>
<br>
-- <br>
2.17.1<br>
<br>
</blockquote></div></div></div></div></div></div>