qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 2/8] virtio: enhance virtio_error messages


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH v2 2/8] virtio: enhance virtio_error messages
Date: Thu, 13 Jul 2017 14:40:02 +0100
User-agent: Mutt/1.8.0 (2017-02-23)

On Thu, Jul 13, 2017 at 01:02:31PM +0200, Ladi Prosek wrote:
> +static const char *virtio_get_device_id(VirtIODevice *vdev)
> +{
> +    DeviceState *qdev = DEVICE(vdev);
> +    while (qdev) {
> +        /* Find the proxy object corresponding to the vdev backend */
> +        Object *prop = object_property_get_link(OBJECT(qdev),
> +                                                VIRTIO_PROP_BACKEND, NULL);
> +        if (prop == OBJECT(vdev)) {
> +            return qdev->id;
> +        }
> +        qdev = qdev->parent_bus->parent;
> +    }
> +    return NULL;
> +}
> +
>  void GCC_FMT_ATTR(2, 3) virtio_error(VirtIODevice *vdev, const char *fmt, 
> ...)
>  {
>      va_list ap;
>  
> +    error_report_nolf("%s (id=%s): ", vdev->name, 
> virtio_get_device_id(vdev));

virtio_get_device_id() can return NULL.  POSIX does not guarantee that
the printf(3) family functions handle "%s", NULL safely.  glibc prints
"(null)" but other libc implementations crash (e.g. Solaris).

http://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html

Should the return NULL above have g_assert_not_reached()?  That would
communicate the assumption that we never reach return NULL and it might
silence static checkers like Coverity but I'm not sure.

Attachment: signature.asc
Description: PGP signature


reply via email to

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