block: Check bdrv_getlength() return value in bdrv_make_zero()
authorKevin Wolf <kwolf@redhat.com>
Mon, 14 Apr 2014 15:03:34 +0000 (17:03 +0200)
committerKevin Wolf <kwolf@redhat.com>
Tue, 22 Apr 2014 09:57:02 +0000 (11:57 +0200)
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
block.c

diff --git a/block.c b/block.c
index ec3fa503dff1e59d8ac824f2fc9321d8ec278345..da558774e8ee0af2ba88b3b5dc2b2ccda6d91f35 100644 (file)
--- a/block.c
+++ b/block.c
@@ -2749,10 +2749,16 @@ int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
  */
 int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags)
 {
-    int64_t target_size = bdrv_getlength(bs) / BDRV_SECTOR_SIZE;
+    int64_t target_size;
     int64_t ret, nb_sectors, sector_num = 0;
     int n;
 
+    target_size = bdrv_getlength(bs);
+    if (target_size < 0) {
+        return target_size;
+    }
+    target_size /= BDRV_SECTOR_SIZE;
+
     for (;;) {
         nb_sectors = target_size - sector_num;
         if (nb_sectors <= 0) {