Skip to content

Commit

Permalink
libbpf-tools: syscall_helpers: fix a warning
Browse files Browse the repository at this point in the history
Fix the following warning when building libbpf-tools:

    syscall_helpers.c: In function ‘init_syscall_names’:
    syscall_helpers.c:63:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
       63 |  fgets(buf, sizeof(buf), f);
          |  ^~~~~~~~~~~~~~~~~~~~~~~~~~

We're not interested in the return value of the first call to fgets, because we
want to skip the first line and in the case of error it will be caught by the
following call to fgets. A funny note is that we can't say just "(void) f()" to
suppress the warning, so I wrote it as "(void) !!f()", which works.

Signed-off-by: Anton Protopopov <[email protected]>
  • Loading branch information
aspsk authored and yonghong-song committed Dec 10, 2020
1 parent 9e7b7b0 commit ee2e88d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libbpf-tools/syscall_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ void init_syscall_names(void)
goto close;
}

/* skip the header */
fgets(buf, sizeof(buf), f);
/* skip the header, ignore the result of fgets, outwit the comiler */
(void) !!fgets(buf, sizeof(buf), f);

while (fgets(buf, sizeof(buf), f)) {
if (buf[strlen(buf) - 1] == '\n')
Expand Down

0 comments on commit ee2e88d

Please sign in to comment.