[libvirt] [PATCH] Fix checking of return codes in dispatcher

Eric Blake eblake at redhat.com
Wed Apr 13 23:29:16 UTC 2011


On 04/13/2011 12:13 PM, Daniel P. Berrange wrote:
> The libvirt APIs reserve any negative value for indicating an
> error. Thus checks
> 
>     if (virXXXX() == -1)
> 
> Should instead be
> 
>     if (virXXXX() < 0)
> 
> * daemon/remote.c: s/ == -1/ < 0/
> ---
>  daemon/remote.c |  339 +++++++++++++++++++++++++++++--------------------------
>  1 files changed, 180 insertions(+), 159 deletions(-)

Why the change in lines?

> @@ -3661,6 +3662,7 @@ remoteDispatchListDefinedNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
>                                    remote_list_defined_networks_ret *ret)
>  {
>      int rv = -1;
> +    int len;
>  
>      if (!conn) {
>          virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
> @@ -3679,12 +3681,12 @@ remoteDispatchListDefinedNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
>          goto cleanup;
>      }
>  
> -    ret->names.names_len =
> -        virConnectListDefinedNetworks(conn,
> +    len = virConnectListDefinedNetworks(conn,
>                                        ret->names.names_val, args->maxnames);
> -    if (ret->names.names_len == -1) {
> +    if (len < 0) {
>          goto cleanup;
>      }
> +    ret->names.names_len = len;

Oh, I see.  You didn't want to change ret until you know the value is valid.

ACK.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110413/e4e97e26/attachment-0001.sig>


More information about the libvir-list mailing list