diff options
-rw-r--r-- | block.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -4144,6 +4144,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, intermediate = top; while (intermediate && intermediate != base) { int pnum_inter; + int64_t total_sectors; ret = bdrv_is_allocated(intermediate, sector_num, nb_sectors, &pnum_inter); if (ret < 0) { @@ -4153,6 +4154,11 @@ int bdrv_is_allocated_above(BlockDriverState *top, return 1; } + total_sectors = bdrv_nb_sectors(intermediate); + if (total_sectors < 0) { + return (int) total_sectors; + } + /* * [sector_num, nb_sectors] is unallocated on top but intermediate * might have @@ -4161,7 +4167,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, */ if (n > pnum_inter && (intermediate == top || - sector_num + pnum_inter < intermediate->total_sectors)) { + sector_num + pnum_inter < total_sectors)) { n = pnum_inter; } |