Re: Is it OK to have compile warnings
On 22/10/13 18:41, Tong Sun wrote:
Hi,
Is it OK to have compile warnings when building a package?
Although sometimes the compiler is just noisy, I don't like ignoring
compiler warnings. They may be a hint of an omission, a bug, or in the
worst case, a security issue.
I prefer to shut the compiler up by fixing the code.
If not,
how can I fix the following:
dial.c: In function 'main':
dial.c:273:8: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
write(fd, buf, bufidx);
I got a bunch of such ignoring-return-value warnings.
Quoting the specification for write() [1]:
"Upon successful completion, write() [...] shall return the number of
bytes actually written to the file associated with fildes. This number
shall never be greater than nbyte. Otherwise, -1 shall be returned and
errno set to indicate the error."
The compiler warning you are getting means that the code isn't
validating the write() return value.
If your write fails you will never catch the error and your application
might crash. Depending on the type of application this can lead to
security issues.
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
Best regards.
Reply to: