On 03/22/2013 07:16 AM, Pavel Hrdina wrote: > Signed-off-by: Pavel Hrdina <phrd...@redhat.com> > --- > qemu-img.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/qemu-img.c b/qemu-img.c > index 21d02bf..34badad 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -322,6 +322,14 @@ static int add_old_style_options(const char *fmt, > QEMUOptionParameter *list, > return 0; > } > > +static void qemu_img_handle_error(Error *err) > +{ > + if (error_is_set(&err)) {
Here you say it is permissible to pass in an unset err,... > + error_report("%s", error_get_pretty(err)); > + error_free(err); > + } > +} > + > static int img_create(int argc, char **argv) > { > int c; > @@ -401,8 +409,7 @@ static int img_create(int argc, char **argv) > bdrv_img_create(filename, fmt, base_filename, base_fmt, > options, img_size, BDRV_O_FLAGS, &local_err, quiet); > if (error_is_set(&local_err)) { > - error_report("%s", error_get_pretty(local_err)); > - error_free(local_err); > + qemu_img_handle_error(local_err); ...which means you are duplicating the error_is_set() call here. > return 1; > } Does it make sense to have qemu_img_handle_error() return a different value according to whether an error was present, so that you could instead write: if (qemu_img_handle_error(local_err) < 0) { return 1; } Or, if all callers are already checking for an actual error before calling qemu_img_handle_error (for other reasons, such as img_create's reason of control flow), should you drop the redundant condition out of the helper function? -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature