[libvirt] [PATCH v14 45/49] add parameter checks to common interfaces

Daniel P. Berrange berrange at redhat.com
Wed Mar 12 15:11:05 UTC 2014


On Fri, Mar 07, 2014 at 06:53:12PM +0800, Chunyan Liu wrote:
> Check NULL parameter inputs
> 
> Signed-off-by: Chunyan Liu <cyliu at suse.com>
> ---
>  src/util/virhostdev.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
> 
> diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
> index 577de48..5f61bfc 100644
> --- a/src/util/virhostdev.c
> +++ b/src/util/virhostdev.c
> @@ -468,6 +468,11 @@ virHostdevPreparePciHostdevs(virHostdevManagerPtr hostdev_mgr,
>      size_t i;
>      int ret = -1;
>  
> +    if (!nhostdevs)
> +        return 0;

This is reasonable because it is an expected case.

> +    if (hostdev_mgr == NULL)
> +        return -1;

This is something that should never happen except by programmer
error, since this is allocated right at libvirtd startup and
then never changed thereafter.

It is preferrable to use ATTRIBUTE_NONNULL() in the header
file for these kind of things.


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list