Patchwork [11/18] usb-linux.c: fix warning with _FORTIFY_SOURCE

login
register
mail settings
Submitter Kirill A. Shutemov
Date Dec. 20, 2009, 1:39 a.m.
Message ID <1261273167-3240-11-git-send-email-kirill@shutemov.name>
Download mbox | patch
Permalink /patch/41497/
State New
Headers show

Comments

Kirill A. Shutemov - Dec. 20, 2009, 1:39 a.m.
CC    usb-linux.o
cc1: warnings being treated as errors
usb-linux.c: In function 'usb_host_read_file':
usb-linux.c:1204: error: ignoring return value of 'fgets', declared with attribute warn_unused_result
make: *** [usb-linux.o] Error 1

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 usb-linux.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
Blue Swirl - Dec. 22, 2009, 7:03 p.m.
On Sun, Dec 20, 2009 at 1:39 AM, Kirill A. Shutemov
<kirill@shutemov.name> wrote:
>  CC    usb-linux.o
> cc1: warnings being treated as errors
> usb-linux.c: In function 'usb_host_read_file':
> usb-linux.c:1204: error: ignoring return value of 'fgets', declared with attribute warn_unused_result
> make: *** [usb-linux.o] Error 1
>
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> ---
>  usb-linux.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/usb-linux.c b/usb-linux.c
> index 88728e9..67bfa7a 100644
> --- a/usb-linux.c
> +++ b/usb-linux.c
> @@ -1201,9 +1201,12 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f
>              device_file);
>     f = fopen(filename, "r");
>     if (f) {
> -        fgets(line, line_size, f);
> +        if (fgets(line, line_size, f))
> +            ret = 1;
> +        else
> +            ret = 0;
> +
>         fclose(f);
> -        ret = 1;

Considering the return values of fgets() and usb_host_read_file(),
this patch looks OK except for the CODING_STYLE violation.

Patch

diff --git a/usb-linux.c b/usb-linux.c
index 88728e9..67bfa7a 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1201,9 +1201,12 @@  static int usb_host_read_file(char *line, size_t line_size, const char *device_f
              device_file);
     f = fopen(filename, "r");
     if (f) {
-        fgets(line, line_size, f);
+        if (fgets(line, line_size, f))
+            ret = 1;
+        else
+            ret = 0;
+
         fclose(f);
-        ret = 1;
 #if 0
     } else {
         if (mon)