qemu-arm
[Top][All Lists]
Advanced

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

Re: [PATCH v2 07/10] qdev: Abort if the root machine container is missin


From: Markus Armbruster
Subject: Re: [PATCH v2 07/10] qdev: Abort if the root machine container is missing
Date: Tue, 21 Jan 2020 13:45:06 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Philippe Mathieu-Daudé <address@hidden> writes:

> The QEMU device API (qdev) relies on having the '/machine'
> container always available.
>
> If it is missing, QEMU will later crash dereferencing a NULL
> pointer, we will get a SEGV, open a debugger, look at the
> backtrace, and figure out we messed with QOM.
> Or we can use g_assert() which abort, displaying the filename
> and line number, so we can quickly open our favorite IDE.
> Prefer the later, to save time to developers.
>
> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
> ---
> v2: New patch
> ---
>  hw/core/qdev.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 58e87d336d..d30cf6320b 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -1143,6 +1143,7 @@ Object *qdev_get_machine(void)
>  
>      if (dev == NULL) {
>          dev = container_get(object_get_root(), "/machine");
> +        g_assert(dev != NULL);
>      }
>  
>      return dev;

container_get()'s contract promises it won't return null.  I think the
assertion belongs there instead.




reply via email to

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