qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* use of uninitialized variable involving visit_type_uint32() and friends
@ 2022-03-31 17:35 Peter Maydell
  2022-03-31 22:27 ` Daniel Henrique Barboza
  2022-04-01  8:07 ` Paolo Bonzini
  0 siblings, 2 replies; 10+ messages in thread
From: Peter Maydell @ 2022-03-31 17:35 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Paolo Bonzini

Coverity warns about use of uninitialized data in what seems
to be a common pattern of use of visit_type_uint32() and similar
functions. Here's an example from target/arm/cpu64.c:

static void cpu_max_set_sve_max_vq(Object *obj, Visitor *v, const char *name,
                                   void *opaque, Error **errp)
{
    ARMCPU *cpu = ARM_CPU(obj);
    uint32_t max_vq;

    if (!visit_type_uint32(v, name, &max_vq, errp)) {
        return;
    }

    [code that does something with max_vq here]
}

This doesn't initialize max_vq, on the apparent assumption
that visit_type_uint32() will do so. But that function is:


bool visit_type_uint32(Visitor *v, const char *name, uint32_t *obj,
                       Error **errp)
{
    uint64_t value;
    bool ok;

    trace_visit_type_uint32(v, name, obj);
    value = *obj;
    ok = visit_type_uintN(v, &value, name, UINT32_MAX, "uint32_t", errp);
    *obj = value;
    return ok;
}

So it reads the value of *obj (the uninitialized max_vq).

What's the right way to write this kind of object-property
setter function? Just pre-initialize the variable to 0?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-06-27 15:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-31 17:35 use of uninitialized variable involving visit_type_uint32() and friends Peter Maydell
2022-03-31 22:27 ` Daniel Henrique Barboza
2022-04-01  8:07 ` Paolo Bonzini
2022-04-01  9:15   ` Markus Armbruster
2022-04-01 11:16     ` Paolo Bonzini
2022-04-01 13:11       ` Markus Armbruster
2022-04-01 15:46         ` Paolo Bonzini
2022-04-04  6:24           ` Markus Armbruster
2022-06-27 13:33   ` Peter Maydell
2022-06-27 15:33     ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).