qemu-img: Fix overwriting 'ret' before using
commit36452f12f877c60f004b34641287d74b14c96208
authorFam Zheng <famz@redhat.com>
Wed, 13 Nov 2013 12:26:49 +0000 (13 20:26 +0800)
committerKevin Wolf <kwolf@redhat.com>
Fri, 15 Nov 2013 12:37:48 +0000 (15 13:37 +0100)
treeb6143061b2e8e840eea8a9769dae61feec456f5d
parenta1144c0dbfa3f820916a135d2d3d6db5635adcc2
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>
qemu-img.c
tests/qemu-iotests/048
tests/qemu-iotests/048.out