qemu-trivial
[Top][All Lists]
Advanced

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

Re: [Qemu-trivial] [PATCH] qom: suppress conscan warning of returning nu


From: Paolo Bonzini
Subject: Re: [Qemu-trivial] [PATCH] qom: suppress conscan warning of returning null point
Date: Sat, 20 Sep 2014 08:24:26 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0

Il 20/09/2014 02:11, Amos Kong ha scritto:
> Conscan complains about g_malloc0() and malloc() return null.
> 
>   Error: NULL_RETURNS (CWE-476):
>   qemu-kvm/qom/object.c:239: returned_null: Function "g_malloc0(gsize)" 
> returns null.
>   qemu-kvm/qom/object.c:239: var_assigned: Assigning: "ti->class" = null 
> return value from "g_malloc0(gsize)".
>   qemu-kvm/qom/object.c:249: dereference: Dereferencing a null pointer 
> "ti->class".
> 
> But if the passed size parameter is >= 1, then we can always get an
> effective pointer, the warning disappears.

The model should handle it:

void *
g_malloc0(size_t n_bytes)
{
    void *mem;
    __coverity_negative_sink__(n_bytes);
    mem = calloc(1, n_bytes == 0 ? 1 : n_bytes);
    if (!mem) __coverity_panic__();
    return mem;
}

So this patch means your coverity runs are misconfigured.

Paolo



reply via email to

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