[03/18] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE

Submitted by Kirill A. Shutemov on Dec. 20, 2009, 1:39 a.m.

Details

Message ID 1261273167-3240-3-git-send-email-kirill@shutemov.name
State New
Headers show

Commit Message

Kirill A. Shutemov Dec. 20, 2009, 1:39 a.m.
CC    posix-aio-compat.o
cc1: warnings being treated as errors
posix-aio-compat.c: In function 'aio_signal_handler':
posix-aio-compat.c:505: error: ignoring return value of 'write', declared with attribute warn_unused_result
make: *** [posix-aio-compat.o] Error 1

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 posix-aio-compat.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Comments

Paul Brook Dec. 20, 2009, 11:02 p.m.
> --- a/posix-aio-compat.c
> +++ b/posix-aio-compat.c
> @@ -502,7 +502,8 @@ static void aio_signal_handler(int signum)
>      if (posix_aio_state) {
>          char byte = 0;
> 
> -  write(posix_aio_state->wfd, &byte, sizeof(byte));
> +  if (write(posix_aio_state->wfd, &byte, sizeof(byte)) != sizeof(byte))
> +    die("write()");

I'm pretty sure this change is wrong, and shows why you should never blindly 
believe dumb analysis tools.

The write may fail harmlessly if the pipe is already full.

Paul

Patch hide | download patch | download mbox

diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index dc14f53..555e263 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -502,7 +502,8 @@  static void aio_signal_handler(int signum)
     if (posix_aio_state) {
         char byte = 0;
 
-        write(posix_aio_state->wfd, &byte, sizeof(byte));
+        if (write(posix_aio_state->wfd, &byte, sizeof(byte)) != sizeof(byte))
+            die("write()");
     }
 
     qemu_service_io();