On Tue, May 17, 2022 at 12:35:07PM +0100, Alberto Faria wrote: > They currently return the value of their 'bytes' parameter on success. > > Make them return 0 instead, for consistency with other I/O functions and > in preparation to implement them using generated_co_wrapper. This also > makes it clear that short reads/writes are not possible. > > Signed-off-by: Alberto Faria <afa...@redhat.com> > ---
> +++ b/qemu-img.c > @@ -5120,30 +5120,27 @@ static int img_dd(int argc, char **argv) > in.buf = g_new(uint8_t, in.bsz); > > for (out_pos = 0; in_pos < size; block_count++) { in_pos, out_pos, and size are int64_t... > - int in_ret, out_ret; > + int bytes, in_ret, out_ret; > > - if (in_pos + in.bsz > size) { > - in_ret = blk_pread(blk1, in_pos, in.buf, size - in_pos); > - } else { > - in_ret = blk_pread(blk1, in_pos, in.buf, in.bsz); > - } > + bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz; ...but in.bsz is int, so declaring 'int bytes' appears safe. Reviewed-by: Eric Blake <ebl...@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org