[Mesa-dev] [PATCH v2 5/5] intel/tools: avoid 'ignoring return value'

Eric Engestrom eric.engestrom at intel.com
Tue Nov 13 17:02:36 UTC 2018


On Tuesday, 2018-11-13 14:19:32 +0200, asimiklit.work at gmail.com wrote:
> From: Andrii Simiklit <andrii.simiklit at globallogic.com>
> 
> 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 at intel.com> )
> 
> Signed-off-by: Andrii Simiklit <andrii.simiklit at globallogic.com>
> ---
>  src/intel/tools/i965_disasm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/intel/tools/i965_disasm.c b/src/intel/tools/i965_disasm.c
> index 73a6760fc1..329f6327ed 100644
> --- a/src/intel/tools/i965_disasm.c
> +++ b/src/intel/tools/i965_disasm.c
> @@ -55,7 +55,8 @@ i965_disasm_read_binary(FILE *fp, size_t *end)
>     if (assembly == NULL)
>        return NULL;
>  
> -   fread(assembly, *end, 1, fp);
> +   MAYBE_UNUSED size_t size = fread(assembly, *end, 1, fp);
> +   assert((size || (*end == 0)) && "error: unable to read all elements!");

I think `*end == 0` should be handled before fread() with an exit(), or
just leave it out from the assert so that it fails here. (Realistically
most people will be using these tools from debug builds anyway.)

>     fclose(fp);
>  
>     return assembly;
> -- 
> 2.17.1
> 


More information about the mesa-dev mailing list