[v2,5/5] intel/tools: avoid 'ignoring return value'

Submitted by andrey simiklit on Nov. 13, 2018, 12:19 p.m.

Details

Message ID 20181113121932.6424-6-asimiklit.work@gmail.com
State New
Headers show
Series "mesa: fix against several compilation warnings" ( rev: 2 ) in Mesa

Not browsing as part of any series.

Commit Message

andrey simiklit Nov. 13, 2018, 12:19 p.m.
From: Andrii Simiklit <andrii.simiklit@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@intel.com> )

Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
---
 src/intel/tools/i965_disasm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

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!");
    fclose(fp);
 
    return assembly;

Comments

On Tuesday, 2018-11-13 14:19:32 +0200, asimiklit.work@gmail.com wrote:
> From: Andrii Simiklit <andrii.simiklit@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@intel.com> )
> 
> Signed-off-by: Andrii Simiklit <andrii.simiklit@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
>