OSDN Git Service

block/raw-posix: Fix preallocating write() loop
authorMax Reitz <mreitz@redhat.com>
Tue, 18 Nov 2014 10:23:04 +0000 (11:23 +0100)
committerKevin Wolf <kwolf@redhat.com>
Tue, 18 Nov 2014 11:08:59 +0000 (12:08 +0100)
write() may write less bytes than requested; in this case, the number of
bytes written is returned. This is the byte count we should be
subtracting from the number of bytes still to be written, and not the
byte count we requested to write.

Reported-by: László Érsek <lersek@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/raw-posix.c

index 414e6d1..e0e48c5 100644 (file)
@@ -1451,7 +1451,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
                                  "Could not write to the new file");
                 break;
             }
-            left -= num;
+            left -= result;
         }
         fsync(fd);
         g_free(buf);