Compilation errors on Ubuntu 8.10 Intrepid Ibex

Eric Benson eric_a_benson at yahoo.com
Tue Nov 11 01:27:43 MSK 2008


Whether it is gcc's bug because cast to void does not suppress the compiler warning, or it is glibc's bug because it declares write() with attribute warn_unused_result, you are unlikely to see a change from either in the near future. The best course is to take it as an opportunity to do some paranoid error checking in these cases. In most cases, there is some better action to be taken when write() fails. In the worst case, such as trying to write a log entry to a full file system, it is better to exit() with non-zero status than to silently continue running. This is why the attribute was added to the declaration of write(). Most projects do not use -Werror, so they only see added compiler output instead of termination of the build process. I agree that it seems like an awfully big change that might adversely affect many mature software projects. However, there is virtually no case when it is correct to ignore an exceptional condition in write().



----- Original Message ----
From: Igor Sysoev <is at rambler-co.ru>
To: nginx at sysoev.ru
Sent: Monday, November 10, 2008 1:43:54 PM
Subject: Re: Compilation errors on Ubuntu 8.10 Intrepid Ibex

On Tue, Nov 11, 2008 at 12:35:40AM +0300, Maxim Dounin wrote:

> Hello!
> 
> On Mon, Nov 10, 2008 at 11:34:37PM +0300, Igor Sysoev wrote:
> 
> > On Mon, Nov 10, 2008 at 09:38:39AM -0800, Eric Benson wrote:
> > 
> > > Compiling either 0.6.32 or 0.7.20 on a new Ubuntu 8.10 installation with gcc 4.3.2 causes errors due to a new compiler warning (when combined with the use of -Werror in CFLAGS). There is now a compiler warning when the return value of write() is ignored. This causes errors in a number of placees in nginx. I have included a log showing the compiler output as well as a patch file showing the changes I made to avoid these errors.
> > 
> > Thank you.
> > However, there is more elegant way to suppress this warning without
> > stub variables:
> > 
> >       (void) write_fd(...)
> > 
> > Could you test the attached patch ?
> 
> No, warn_unused_result warning can't be avoided by casting to 
> void: 
> 
> $ cat unused.c
> int foo() __attribute__((warn_unused_result));
> 
> int
> foo()
> {
>         return 1;
> }
> 
> int
> main()
> {
>         (void) foo();
> 
>         return 0;
> }
> $ gcc unused.c
> unused.c: In function 'main':
> unused.c:12: warning: ignoring return value of 'foo', declared with attribute warn_unused_result
> 
> More details here:
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509
> 
> However I don't think it's a good idea to use stub variables.  
> Probably something like
> 
>     if (ngx_write_fd(...) == NGX_FILE_ERROR) {
>         /* void */
>     }
> 
> would be better.
> 
> Maxim Dounin
> 
> p.s. Actually I think that it's glibc's bug.  But we probably have 
> to live with it, at least for some time.

I believe this is gcc bug because I explictly says that I do not need
the function result using (void) case.

Dummy result checking as well as stub variable are security/reliabilty
profanation.  The (void) cast should be compact way to do the same.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list