aboutsummaryrefslogtreecommitdiff
path: root/qemu-io-cmds.c
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2016-06-20 16:26:22 +0200
committerMax Reitz <mreitz@redhat.com>2016-07-13 13:41:38 +0200
commita367467995d0528fe591d87ca2e437c7b7d7951b (patch)
tree62d189bc598769a9624e86f25ab7de0cc473f753 /qemu-io-cmds.c
parent84c26520d3c1c9ff4a10455748139463278816d5 (diff)
qemu-io: Use correct range limitations
create_iovec() has a comment lamenting the lack of SIZE_T_MAX. Since there actually is a SIZE_MAX, use it. Two places use INT_MAX for checking the upper bound of a sector count that is used as an argument for a blk_*() function (blk_discard() and blk_write_compressed(), respectively). BDRV_REQUEST_MAX_SECTORS should be used instead. And finally, do_co_pwrite_zeroes() used to similarly check that the sector count does not exceed INT_MAX. However, this function is now backed by blk_co_pwrite_zeroes() which takes bytes as an argument instead of sectors. Therefore, it should be the byte count that does not exceed INT_MAX, not the sector count. Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'qemu-io-cmds.c')
-rw-r--r--qemu-io-cmds.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 40fe2ebf7d..6e29edb1fd 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -389,9 +389,9 @@ create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_iov,
goto fail;
}
- /* should be SIZE_T_MAX, but that doesn't exist */
- if (len > INT_MAX) {
- printf("Argument '%s' exceeds maximum size %d\n", arg, INT_MAX);
+ if (len > SIZE_MAX) {
+ printf("Argument '%s' exceeds maximum size %llu\n", arg,
+ (unsigned long long)SIZE_MAX);
goto fail;
}
@@ -479,7 +479,7 @@ static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
.done = false,
};
- if (count >> BDRV_SECTOR_BITS > INT_MAX) {
+ if (count > INT_MAX) {
return -ERANGE;
}
@@ -500,7 +500,7 @@ static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset,
{
int ret;
- if (count >> 9 > INT_MAX) {
+ if (count >> 9 > BDRV_REQUEST_MAX_SECTORS) {
return -ERANGE;
}
@@ -1688,9 +1688,9 @@ static int discard_f(BlockBackend *blk, int argc, char **argv)
if (count < 0) {
print_cvtnum_err(count, argv[optind]);
return 0;
- } else if (count >> BDRV_SECTOR_BITS > INT_MAX) {
+ } else if (count >> BDRV_SECTOR_BITS > BDRV_REQUEST_MAX_SECTORS) {
printf("length cannot exceed %"PRIu64", given %s\n",
- (uint64_t)INT_MAX << BDRV_SECTOR_BITS,
+ (uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS,
argv[optind]);
return 0;
}