diff mbox

[04/14] block/qcow.c: fix warnings with _FORTIFY_SOURCE

Message ID 1262223199-19062-4-git-send-email-kirill@shutemov.name
State New
Headers show

Commit Message

Kirill A . Shutemov Dec. 31, 2009, 1:33 a.m. UTC
CC    block/qcow.o
cc1: warnings being treated as errors
block/qcow.c: In function 'qcow_create':
block/qcow.c:804: error: ignoring return value of 'write', declared with attribute warn_unused_result
block/qcow.c:806: error: ignoring return value of 'write', declared with attribute warn_unused_result
block/qcow.c:811: error: ignoring return value of 'write', declared with attribute warn_unused_result
make: *** [block/qcow.o] Error 1

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 block/qcow.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

Comments

malc Dec. 31, 2009, 2:01 a.m. UTC | #1
On Thu, 31 Dec 2009, Kirill A. Shutemov wrote:

>   CC    block/qcow.o
> cc1: warnings being treated as errors
> block/qcow.c: In function 'qcow_create':
> block/qcow.c:804: error: ignoring return value of 'write', declared with attribute warn_unused_result
> block/qcow.c:806: error: ignoring return value of 'write', declared with attribute warn_unused_result
> block/qcow.c:811: error: ignoring return value of 'write', declared with attribute warn_unused_result
> make: *** [block/qcow.o] Error 1
> 
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> ---
>  block/qcow.c |   26 ++++++++++++++++++++++----
>  1 files changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/block/qcow.c b/block/qcow.c
> index 7fc85ae..472494c 100644
> --- a/block/qcow.c
> +++ b/block/qcow.c
> @@ -750,6 +750,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options)
>      int64_t total_size = 0;
>      const char *backing_file = NULL;
>      int flags = 0;
> +    int ret;
>  
>      /* Read out options */
>      while (options && options->name) {
> @@ -801,17 +802,34 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options)
>      }
>  
>      /* write all the data */
> -    write(fd, &header, sizeof(header));
> +    ret = qemu_write_full(fd, &header, sizeof(header));
> +    if (ret != sizeof(header)) {
> +        ret = -errno;
> +        goto exit;
> +    }
> +
>      if (backing_file) {
> -        write(fd, backing_file, backing_filename_len);
> +        ret = qemu_write_full(fd, backing_file, backing_filename_len);
> +        if (ret != backing_filename_len) {
> +            ret = -errno;
> +            goto exit;
> +        }
> +
>      }
>      lseek(fd, header_size, SEEK_SET);

Surprising that lseek's return value is not marked warn_unused_result.

>      tmp = 0;
>      for(i = 0;i < l1_size; i++) {
> -        write(fd, &tmp, sizeof(tmp));
> +        ret = qemu_write_full(fd, &tmp, sizeof(tmp));
> +        if (ret != sizeof(tmp)) {
> +            ret = -errno;
> +            goto exit;
> +        }
>      }
> +
> +    ret = 0;
> +exit:
>      close(fd);
> -    return 0;
> +    return ret;
>  }
>  
>  static int qcow_make_empty(BlockDriverState *bs)
>
Paolo Bonzini Dec. 31, 2009, 7:57 a.m. UTC | #2
On 12/31/2009 03:01 AM, malc wrote:
>> >        lseek(fd, header_size, SEEK_SET);
>
> Surprising that lseek's return value is not marked warn_unused_result.

Probably because it's guaranteed not to fail because of I/O errors:

ERRORS
        EBADF  fd is not an open file descriptor.

        EINVAL whence is not  one  of  SEEK_SET,  SEEK_CUR,  SEEK_END;
               or the resulting file offset would be negative, or
               beyond the end of a seekable device.

        EOVERFLOW
               The resulting file offset cannot be represented in an
               off_t.

        ESPIPE fd is associated with a pipe, socket, or FIFO.
diff mbox

Patch

diff --git a/block/qcow.c b/block/qcow.c
index 7fc85ae..472494c 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -750,6 +750,7 @@  static int qcow_create(const char *filename, QEMUOptionParameter *options)
     int64_t total_size = 0;
     const char *backing_file = NULL;
     int flags = 0;
+    int ret;
 
     /* Read out options */
     while (options && options->name) {
@@ -801,17 +802,34 @@  static int qcow_create(const char *filename, QEMUOptionParameter *options)
     }
 
     /* write all the data */
-    write(fd, &header, sizeof(header));
+    ret = qemu_write_full(fd, &header, sizeof(header));
+    if (ret != sizeof(header)) {
+        ret = -errno;
+        goto exit;
+    }
+
     if (backing_file) {
-        write(fd, backing_file, backing_filename_len);
+        ret = qemu_write_full(fd, backing_file, backing_filename_len);
+        if (ret != backing_filename_len) {
+            ret = -errno;
+            goto exit;
+        }
+
     }
     lseek(fd, header_size, SEEK_SET);
     tmp = 0;
     for(i = 0;i < l1_size; i++) {
-        write(fd, &tmp, sizeof(tmp));
+        ret = qemu_write_full(fd, &tmp, sizeof(tmp));
+        if (ret != sizeof(tmp)) {
+            ret = -errno;
+            goto exit;
+        }
     }
+
+    ret = 0;
+exit:
     close(fd);
-    return 0;
+    return ret;
 }
 
 static int qcow_make_empty(BlockDriverState *bs)