qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 04/11] snapshot: new function bdrv_snapshot_find


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH 04/11] snapshot: new function bdrv_snapshot_find_by_id_and_name()
Date: Tue, 11 Jun 2013 10:26:25 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Jun 08, 2013 at 02:58:00PM +0800, Wenchao Xia wrote:
> +    if (id && name) {
> +        for (i = 0; i < nb_sns; i++) {
> +            sn = &sn_tab[i];
> +            if (!strcmp(sn->id_str, id) && !strcmp(sn->name, name)) {
> +                *sn_info = *sn;
> +                ret = true;
> +                break;
> +            }
> +        }
> +    } else if (id) {
> +        for (i = 0; i < nb_sns; i++) {
> +            sn = &sn_tab[i];
> +            if (!strcmp(sn->id_str, id)) {
> +                *sn_info = *sn;
> +                ret = true;
> +                break;
> +            }
> +        }
> +    } else if (name) {
> +        for (i = 0; i < nb_sns; i++) {
> +            sn = &sn_tab[i];
> +            if (!strcmp(sn->name, name)) {
> +                *sn_info = *sn;
> +                ret = true;
> +                break;
> +            }
> +        }
> +    } else {
> +        /* program error */
> +        abort();
> +    }

If you respin, this would be a little clearer:

assert(id || name);

if (id && name) {
    ...
} else if (id) {
    ...
} else if (name) {
    ...
}

The advantage is that the assert(3) condition is included in the error
message that gets printed.

Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]