unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values
@ 2009-11-23  6:20 Dirk-Jan C. Binnema
  2009-11-23  7:34 ` Karl Wiberg
  0 siblings, 1 reply; 8+ messages in thread
From: Dirk-Jan C. Binnema @ 2009-11-23  6:20 UTC (permalink / raw)
  To: notmuch@notmuchmail org

From: Dirk-Jan C. Binnema <djcb.bulk@gmail.com>
Date: Mon, 23 Nov 2009 08:03:35 +0200


---
 notmuch-new.c |    4 +++-
 notmuch-tag.c |    4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index a2b30bd..3d04efa 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -35,8 +35,10 @@ static volatile sig_atomic_t interrupted;
 static void
 handle_sigint (unused (int sig))
 {
+    ssize_t ignored;
     static char msg[] = "Stopping...         \n";
-    write(2, msg, sizeof(msg)-1);
+    
+    ignored = write(2, msg, sizeof(msg)-1);
     interrupted = 1;
 }
 
diff --git a/notmuch-tag.c b/notmuch-tag.c
index e2311f6..ec98c3b 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -25,8 +25,10 @@ static volatile sig_atomic_t interrupted;
 static void
 handle_sigint (unused (int sig))
 {
+    ssize_t ignored;
+	
     static char msg[] = "Stopping...         \n";
-    write(2, msg, sizeof(msg)-1);
+    ignored = write(2, msg, sizeof(msg)-1);
     interrupted = 1;
 }
 
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values
  2009-11-23  6:20 [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values Dirk-Jan C. Binnema
@ 2009-11-23  7:34 ` Karl Wiberg
  2009-11-23 11:11   ` Dirk-Jan Binnema
  0 siblings, 1 reply; 8+ messages in thread
From: Karl Wiberg @ 2009-11-23  7:34 UTC (permalink / raw)
  To: djcb; +Cc: notmuch@notmuchmail org

On Mon, Nov 23, 2009 at 7:20 AM, Dirk-Jan C. Binnema
<djcb.bulk@gmail.com> wrote:

> +    ssize_t ignored;
>     static char msg[] = "Stopping...         \n";
> -    write(2, msg, sizeof(msg)-1);
> +
> +    ignored = write(2, msg, sizeof(msg)-1);
>     interrupted = 1;
>  }

Didn't the "(void)" suggestion work?

-- 
Karl Wiberg, kha@treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values
  2009-11-23  7:34 ` Karl Wiberg
@ 2009-11-23 11:11   ` Dirk-Jan Binnema
  2009-11-23 13:19     ` Karl Wiberg
  0 siblings, 1 reply; 8+ messages in thread
From: Dirk-Jan Binnema @ 2009-11-23 11:11 UTC (permalink / raw)
  To: Karl Wiberg; +Cc: notmuch@notmuchmail org, djcb

[-- Attachment #1: Type: text/plain, Size: 524 bytes --]

On Mon, Nov 23, 2009 at 9:34 AM, Karl Wiberg <kha@treskal.com> wrote:

> On Mon, Nov 23, 2009 at 7:20 AM, Dirk-Jan C. Binnema
> <djcb.bulk@gmail.com> wrote:
>
> > +    ssize_t ignored;
> >     static char msg[] = "Stopping...         \n";
> > -    write(2, msg, sizeof(msg)-1);
> > +
> > +    ignored = write(2, msg, sizeof(msg)-1);
> >     interrupted = 1;
> >  }
>
> Didn't the "(void)" suggestion work?
>
>
I actually preferred that solution, but unfortunately, it didn't stop gcc
from complaining...

Best wishes,
Dirk.

[-- Attachment #2: Type: text/html, Size: 978 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values
  2009-11-23 11:11   ` Dirk-Jan Binnema
@ 2009-11-23 13:19     ` Karl Wiberg
  2009-11-23 14:24       ` Jed Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Karl Wiberg @ 2009-11-23 13:19 UTC (permalink / raw)
  To: Dirk-Jan Binnema; +Cc: notmuch@notmuchmail org, djcb

On Mon, Nov 23, 2009 at 12:11 PM, Dirk-Jan Binnema <djcb.bulk@gmail.com> wrote:

> On Mon, Nov 23, 2009 at 9:34 AM, Karl Wiberg <kha@treskal.com> wrote:
>
> > Didn't the "(void)" suggestion work?
>
> I actually preferred that solution, but unfortunately, it didn't
> stop gcc from complaining...

Hmpf. I'd argue that that's a gcc bug, forcing the user to use an
unnecessarily complicated way to pretend to use the return value. Oh
well.

-- 
Karl Wiberg, kha@treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values
  2009-11-23 13:19     ` Karl Wiberg
@ 2009-11-23 14:24       ` Jed Brown
  2009-11-23 16:14         ` Dirk-Jan Binnema
  2009-12-01 15:57         ` Carl Worth
  0 siblings, 2 replies; 8+ messages in thread
From: Jed Brown @ 2009-11-23 14:24 UTC (permalink / raw)
  To: Karl Wiberg, Dirk-Jan Binnema; +Cc: notmuch@notmuchmail org, djcb

On Mon, 23 Nov 2009 14:19:18 +0100, Karl Wiberg <kha@treskal.com> wrote:
> On Mon, Nov 23, 2009 at 12:11 PM, Dirk-Jan Binnema <djcb.bulk@gmail.com> wrote:
> 
> > On Mon, Nov 23, 2009 at 9:34 AM, Karl Wiberg <kha@treskal.com> wrote:
> >
> > > Didn't the "(void)" suggestion work?
> >
> > I actually preferred that solution, but unfortunately, it didn't
> > stop gcc from complaining...
> 
> Hmpf. I'd argue that that's a gcc bug, forcing the user to use an
> unnecessarily complicated way to pretend to use the return value. Oh
> well.

From the gcc man page:

       -Wunused-value
           Warn whenever a statement computes a result that is explicitly
           not used. To suppress this warning cast the unused expression
           to void. This includes an expression-statement or the left-
           hand side of a comma expression that contains no side effects.
           For example, an expression such as x[i,j] will cause a
           warning, while x[(void)i,j] will not.

           This warning is enabled by -Wall.


But I'm confused here because I don't currently see any warnings with
gcc-4.4.2.  Actually this must be a bug because I get no warnings for
the blatantly unused

  malloc(5);

with -Wall -Wextra -pedantic.  Anyway, if your system headers specify
__attribute__((warn_unused_result)) for write, then you could be running
into this bug/feature

  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35579


Jed

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values
  2009-11-23 14:24       ` Jed Brown
@ 2009-11-23 16:14         ` Dirk-Jan Binnema
  2009-11-23 16:38           ` Jed Brown
  2009-12-01 15:57         ` Carl Worth
  1 sibling, 1 reply; 8+ messages in thread
From: Dirk-Jan Binnema @ 2009-11-23 16:14 UTC (permalink / raw)
  To: Jed Brown; +Cc: notmuch@notmuchmail org, djcb

[-- Attachment #1: Type: text/plain, Size: 369 bytes --]

Hi Jed,

On Mon, Nov 23, 2009 at 4:24 PM, Jed Brown <jed@59a2.org> wrote:

>
>
> But I'm confused here because I don't currently see any warnings with
> gcc-4.4.2.  Actually this must be a bug because I get no warnings for
> the blatantly unused
>
>  malloc(5);
>

Did you try it with -O2? Without optimizations many of the warnings are not
issued.

Best wishes,
Dirk.

[-- Attachment #2: Type: text/html, Size: 672 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values
  2009-11-23 16:14         ` Dirk-Jan Binnema
@ 2009-11-23 16:38           ` Jed Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Jed Brown @ 2009-11-23 16:38 UTC (permalink / raw)
  To: Dirk-Jan Binnema, Jed Brown; +Cc: notmuch@notmuchmail org, djcb

On Mon, 23 Nov 2009 18:14:12 +0200, Dirk-Jan Binnema <djcb.bulk@gmail.com> wrote:
> Did you try it with -O2? Without optimizations many of the warnings are not
> issued.

Yes,

$ cat > foo.c
#include <stdlib.h>
#include <unistd.h>
int main()
{
  malloc(5);
  write(2,0,10);
  return 0;
}
$ gcc -static -std=c89 -O0 -Wall -Wextra -pedantic -o foo foo.c
$ objdump -d -M intel foo |grep -A12 '<main>'
00000000004002a4 <main>:
  4002a4:       55                      push   rbp
  4002a5:       48 89 e5                mov    rbp,rsp
  4002a8:       bf 05 00 00 00          mov    edi,0x5
  4002ad:       e8 6e 61 00 00          call   406420 <__libc_malloc>
  4002b2:       ba 0a 00 00 00          mov    edx,0xa
  4002b7:       be 00 00 00 00          mov    esi,0x0
  4002bc:       bf 02 00 00 00          mov    edi,0x2
  4002c1:       e8 ea a0 00 00          call   40a3b0 <__libc_write>
  4002c6:       b8 00 00 00 00          mov    eax,0x0
  4002cb:       c9                      leave  
  4002cc:       c3                      ret    
  4002cd:       90                      nop
$ gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic
Thread model: posix
gcc version 4.4.2 (GCC)
$ uname -a
Linux kunyang 2.6.31-ARCH #1 SMP PREEMPT Tue Nov 10 19:01:40 CET 2009 x86_64 Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz GenuineIntel GNU/Linux


Seems fishy.

Jed

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values
  2009-11-23 14:24       ` Jed Brown
  2009-11-23 16:14         ` Dirk-Jan Binnema
@ 2009-12-01 15:57         ` Carl Worth
  1 sibling, 0 replies; 8+ messages in thread
From: Carl Worth @ 2009-12-01 15:57 UTC (permalink / raw)
  To: Jed Brown, Karl Wiberg, Dirk-Jan Binnema; +Cc: notmuch@notmuchmail org, djcb

[-- Attachment #1: Type: text/plain, Size: 1572 bytes --]

On Mon, 23 Nov 2009 15:24:46 +0100, Jed Brown <jed@59A2.org> wrote:
> >From the gcc man page:
> 
>        -Wunused-value
>            Warn whenever a statement computes a result that is explicitly
>            not used. To suppress this warning cast the unused expression
>            to void. This includes an expression-statement or the left-
>            hand side of a comma expression that contains no side effects.
>            For example, an expression such as x[i,j] will cause a
>            warning, while x[(void)i,j] will not.
> 
>            This warning is enabled by -Wall.
> 
> But I'm confused here because I don't currently see any warnings with
> gcc-4.4.2.  Actually this must be a bug because I get no warnings for
> the blatantly unused
> 
>   malloc(5);

I'm guessing that the -Wunused-value warning doesn't consider values
computed by function calls.

> with -Wall -Wextra -pedantic.  Anyway, if your system headers specify
> __attribute__((warn_unused_result)) for write, then you could be running
> into this bug/feature
> 
>   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35579

Yes, this is the attribute that's triggering the warnings. I poked
around in the glibc headers to see how to get this warning myself, and I
finally found:

	make CFLAGS="-O -D_FORTIFY_SOURCE"

That makes the warning appear even with gcc 4.3.4, (and the definitions
in the headers suggest it will work with any gcc >= 4.1).

So I've pushed the patch now, (with an updated commit message to reflect
the above analysis).

-Carl

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-12-01 15:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-23  6:20 [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values Dirk-Jan C. Binnema
2009-11-23  7:34 ` Karl Wiberg
2009-11-23 11:11   ` Dirk-Jan Binnema
2009-11-23 13:19     ` Karl Wiberg
2009-11-23 14:24       ` Jed Brown
2009-11-23 16:14         ` Dirk-Jan Binnema
2009-11-23 16:38           ` Jed Brown
2009-12-01 15:57         ` Carl Worth

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).