Mailing List Archive

Patch for Exim 4.91 compile warning
All,

When compiling Exim 4.91 on Ubuntu 16.04.5 LTS I get a gcc warning in
the USR1 signal handler:

gcc exim.c
exim.c: In function ‘usr1_handler’:
exim.c:242:1: warning: ignoring return value of ‘write’, declared with
attribute warn_unused_result [-Wunused-result]
 (void)write(fd, process_info, process_info_len);
 ^
gcc expand.c

The following patch addresses the issue and should be safe for all
platforms:

root@relay1:~/exim-4.91/src# diff exim.c-orig exim.c
240c240,251
< if (fd < 0) return;
---
> //if (fd < 0) return;
> //
> //(void)write(fd, process_info, process_info_len);
> //(void)close(fd);
>
> if (fd > 0) {
>   ssize_t x;
>   int y;
>
>   x = write(fd, process_info, process_info_len);
>   y = close(fd);
>   }
242,243d252
< (void)write(fd, process_info, process_info_len);
< (void)close(fd);


Regards


Mike Tubby MJT4-RIPE



--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Patch for Exim 4.91 compile warning [ In reply to ]
Mike Tubby via Exim-users <exim-users@exim.org> (Mi 16 Jan 2019 14:58:07 CET):
> All,
>
> When compiling Exim 4.91 on Ubuntu 16.04.5 LTS I get a gcc warning in the
> USR1 signal handler:
>
> gcc exim.c
> exim.c: In function ‘usr1_handler’:
> exim.c:242:1: warning: ignoring return value of ‘write’, declared with
> attribute warn_unused_result [-Wunused-result]
>  (void)write(fd, process_info, process_info_len);
>  ^
> gcc expand.c

On a curent Debian this attribute isn't used for the write(2)
call. Hm. Intentional?

> > if (fd > 0) {
> >   ssize_t x;
> >   int y;
> >
> >   x = write(fd, process_info, process_info_len);
> >   y = close(fd);
> >   }
> 242,243d252
> < (void)write(fd, process_info, process_info_len);
> < (void)close(fd);

While (void) write(…) seems to express clearly the intention,
I'm not sure why GCC does not understand it (anymore, not yet?)

Beside from your proposal using a dummy variable, I found another
way

if (write(…));
if (close(…));

But it needs a comment or a macro like

#define IGNORE_RESULT(x) if(x)

IGNORE_RESULT(write(…))

--
Heiko
Re: Patch for Exim 4.91 compile warning [ In reply to ]
On 16/01/2019 14:31, Heiko Schlittermann via Exim-users wrote:
> Mike Tubby via Exim-users <exim-users@exim.org> (Mi 16 Jan 2019 14:58:07 CET):
>> All,
>>
>> When compiling Exim 4.91 on Ubuntu 16.04.5 LTS I get a gcc warning in the
>> USR1 signal handler:
>>
>> gcc exim.c
>> exim.c: In function ?usr1_handler?:
>> exim.c:242:1: warning: ignoring return value of ?write?, declared with
>> attribute warn_unused_result [-Wunused-result]
>> ?(void)write(fd, process_info, process_info_len);
>> ?^
>> gcc expand.c
> On a curent Debian this attribute isn't used for the write(2)
> call. Hm. Intentional?
>
>>> if (fd > 0) {
>>> ?? ssize_t x;
>>> ?? int y;
>>>
>>> ?? x = write(fd, process_info, process_info_len);
>>> ?? y = close(fd);
>>> ?? }
>> 242,243d252
>> < (void)write(fd, process_info, process_info_len);
>> < (void)close(fd);
> While (void) write(?) seems to express clearly the intention,
> I'm not sure why GCC does not understand it (anymore, not yet?)

Heiko, I completely agree with the intention of:

??? (void)function(...)

and have used it many times myself over the years - I can only guess
that the makefile with GCC 5.4.0 options turns back on something that
makes this a warning again.

Here's the GCC version:

root@relay1:~/exim-4.91# gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.? There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

>
> Beside from your proposal using a dummy variable, I found another
> way
>
> if (write(?));
> if (close(?));
>
> But it needs a comment or a macro like
>
> #define IGNORE_RESULT(x) if(x)
> ?
> IGNORE_RESULT(write(?))

Agreed but this is getting even more messy ;-)


Regards

Mike


> --
> Heiko
>
--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Patch for Exim 4.91 compile warning [ In reply to ]
On 16/01/2019 14:31, Heiko Schlittermann via Exim-users wrote:
> Mike Tubby via Exim-users <exim-users@exim.org> (Mi 16 Jan 2019 14:58:07 CET):
>> When compiling Exim 4.91 on Ubuntu 16.04.5 LTS I get a gcc warning in the
>> USR1 signal handler:
>>
>> gcc exim.c
>> exim.c: In function ?usr1_handler?:
>> exim.c:242:1: warning: ignoring return value of ?write?, declared with
>> attribute warn_unused_result [-Wunused-result]
>> ?(void)write(fd, process_info, process_info_len);
>> ?^

We have in the past refused to bow to such pressure for
pointless attempts to silence stupid static analysis
warnings.

There is _zero_ that can usefully be done with that return
value.
--
Cheers,
Jeremy


--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/