What's the best way to fix warnings from unused result
Fred Wright
fw at fwright.net
Sun Apr 7 17:19:47 UTC 2019
On Sun, 7 Apr 2019, Eric S. Raymond via devel wrote:
> Hal Murray via devel <devel at ntpsec.org>:
>> ../../ntpd/nts.c:213:9: warning: ignoring return value of ???strerror_r???,
>> declared with attribute warn_unused_result [-Wunused-result]
>>
>> I'm only getting this on Ubuntu, so a secondary question is why isn't that
>> check happening on other systems?
>
> Probablty compiler version. As GCC has evolved it has gotten stricter
> about this sort of thing.
>
>>> From the man page:
>> int strerror_r(int errnum, char *buf, size_t buflen);
>> /* XSI-compliant */
>>
>> char *strerror_r(int errnum, char *buf, size_t buflen);
>> /* GNU-specific */
>>
>> I don't know or care which version we get. It's different on different
>> systems, so to save the result then say UNUSED_LOCAL gets slightly complicated.
>
> This is probably what you want:
>
> ./include/ntp_stdlib.h:162:#define IGNORE(r) do{if(r){}}while(0)
Does a simple void cast work? E.g.:
(void) strerror_r(...)
It certainly works for unused function arguments, and it's an actual
official language feature for explicitly discarding results. Granted, I
know of one compiler that doesn't like it, but it's an oddball.
Fred Wright
More information about the devel
mailing list