aboutsummaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2013-11-13 20:26:49 +0800
committerKevin Wolf <kwolf@redhat.com>2013-11-15 13:37:48 +0100
commit36452f12f877c60f004b34641287d74b14c96208 (patch)
treeb6143061b2e8e840eea8a9769dae61feec456f5d /qemu-img.c
parenta1144c0dbfa3f820916a135d2d3d6db5635adcc2 (diff)
downloadqemu-36452f12f877c60f004b34641287d74b14c96208.zip
qemu-36452f12f877c60f004b34641287d74b14c96208.tar.gz
qemu-36452f12f877c60f004b34641287d74b14c96208.tar.bz2
qemu-img: Fix overwriting 'ret' before using
This patch moves ret assignment after reporting original error. We were lucky to pass qemu-iotests 048 (qemu-img compare case) but when I tried to run with TEST_DIR=/tmp (tmpfs), it fails with a "wrong" mismatch offset. This fixes two bugs. In the first if branch, setting ret to 1 before using it makes dead code in the next line: pnum is never added to mismatch offset even if ret was 0. In the other if branch, currently the output error is always -4: strerror(-4) -> Unknown error -4 Added regression test in case 048. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Amos Kong <akong@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com>
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/qemu-img.c b/qemu-img.c
index bf3fb4f..b6b5644 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1020,10 +1020,10 @@ static int img_compare(int argc, char **argv)
}
ret = compare_sectors(buf1, buf2, nb_sectors, &pnum);
if (ret || pnum != nb_sectors) {
- ret = 1;
qprintf(quiet, "Content mismatch at offset %" PRId64 "!\n",
sectors_to_bytes(
ret ? sector_num : sector_num + pnum));
+ ret = 1;
goto out;
}
}
@@ -1045,9 +1045,9 @@ static int img_compare(int argc, char **argv)
}
if (ret) {
if (ret < 0) {
- ret = 4;
error_report("Error while reading offset %" PRId64 ": %s",
sectors_to_bytes(sector_num), strerror(-ret));
+ ret = 4;
}
goto out;
}
@@ -1092,10 +1092,10 @@ static int img_compare(int argc, char **argv)
filename_over, buf1, quiet);
if (ret) {
if (ret < 0) {
- ret = 4;
error_report("Error while reading offset %" PRId64
" of %s: %s", sectors_to_bytes(sector_num),
filename_over, strerror(-ret));
+ ret = 4;
}
goto out;
}