bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: enable -Werror for lib/ in coreutils


From: Bruno Haible
Subject: Re: enable -Werror for lib/ in coreutils
Date: Wed, 28 Oct 2009 01:07:28 +0100
User-agent: KMail/1.9.9

Jim Meyering wrote:
> build (--enable-gcc-warnings): enable gcc's -Werror also in lib/

Does your README-hacking file say that building with
--enable-gcc-warnings is only supported on glibc systems with
recent enough GCC? It is known that on other platforms and with
older GCC versions, gcc shows many warnings, most of which are
irrelevant. I don't want to spend time on reducing the number of
pointless warnings on non-glibc platforms, since we are not using
these for productive development (except maybe Eric). My goal with
gnulib is to get code written for POSIX or glibc systems compile
fine, producing correct executables. Minimizing the verbosity of
the build log on non-glibc platforms is not a goal for me.

> +--- a/lib/unicodeio.c
> ++++ b/lib/unicodeio.c
> +@@ -38,6 +38,7 @@
> +
> + #include "localcharset.h"
> + #include "unistr.h"
> ++#include "ignore-value.h"
> +
> + /* When we pass a Unicode character to iconv(), we must pass it in a
> +    suitable encoding. The standardized Unicode encodings are
> +@@ -162,7 +163,7 @@ fwrite_success_callback (const char *buf, size_t buflen, 
> void *callback_arg)
> + {
> +   FILE *stream = (FILE *) callback_arg;
> +
> +-  fwrite (buf, 1, buflen, stream);
> ++  ignore_value (fwrite (buf, 1, buflen, stream));
> +   return 0;
> + }
> +

gcc's warning is formally justified here. Ignoring the return value of
a function marked with __attribute__((__warn_unused_result__ )) warrants
a comment. I'm adding one like this:


2009-10-27  Jim Meyering  <address@hidden>
            Bruno Haible  <address@hidden>

        Avoid warning despite dropping the return value of fwrite.
        * lib/unicodeio.c: Include ignore-value.h.
        (fwrite_success_callback): Explicitly ignore fwrite's return value.
        * modules/unicodeio (Depends-on): Add ignore-value.

--- lib/unicodeio.c.orig        2009-10-28 00:51:17.000000000 +0100
+++ lib/unicodeio.c     2009-10-28 00:47:44.000000000 +0100
@@ -1,6 +1,6 @@
 /* Unicode character output to streams with locale dependent encoding.
 
-   Copyright (C) 2000-2003, 2006, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2000-2003, 2006, 2008-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -38,6 +38,7 @@
 
 #include "localcharset.h"
 #include "unistr.h"
+#include "ignore-value.h"
 
 /* When we pass a Unicode character to iconv(), we must pass it in a
    suitable encoding. The standardized Unicode encodings are
@@ -162,7 +163,11 @@
 {
   FILE *stream = (FILE *) callback_arg;
 
-  fwrite (buf, 1, buflen, stream);
+  /* The return value of fwrite can be ignored here, because under normal
+     conditions (STREAM is an open stream and not wide-character oriented)
+     when fwrite() returns a value != buflen it also sets STREAM's error
+     indicator.  */
+  ignore_value (fwrite (buf, 1, buflen, stream));
   return 0;
 }
 
--- modules/unicodeio.orig      2009-10-28 00:51:17.000000000 +0100
+++ modules/unicodeio   2009-10-28 00:44:30.000000000 +0100
@@ -13,6 +13,7 @@
 gettext-h
 localcharset
 error
+ignore-value
 
 configure.ac:
 gl_UNICODEIO




reply via email to

[Prev in Thread] Current Thread [Next in Thread]