qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] qapi-commands.py generates code that uses uninitialized variables
@ 2014-03-17 23:58 Peter Maydell
  2014-03-18  9:32 ` Markus Armbruster
  0 siblings, 1 reply; 12+ messages in thread
From: Peter Maydell @ 2014-03-17 23:58 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Michael Roth, Anthony Liguori

This is something clang's -fsanitize=undefined spotted. The
code generated by qapi-commands.py in qmp-marshal.c for
qmp_marshal_* functions where there are some optional
arguments looks like this:

    bool has_force = false;
    bool force;

    mi = qmp_input_visitor_new_strict(QOBJECT(args));
    v = qmp_input_get_visitor(mi);
    visit_type_str(v, &device, "device", errp);
    visit_start_optional(v, &has_force, "force", errp);
    if (has_force) {
        visit_type_bool(v, &force, "force", errp);
    }
    visit_end_optional(v, errp);
    qmp_input_visitor_cleanup(mi);

    if (error_is_set(errp)) {
        goto out;
    }
    qmp_eject(device, has_force, force, errp);

In the case where has_force is false, we never initialize
force, but then we use it by passing it to qmp_eject.
I imagine we don't then actually use the value, but clang
complains in particular for 'bool' variables because the value
that ends up being loaded from memory for 'force' is not either
0 or 1 (being uninitialized stack contents).

Anybody understand what the codegenerator is doing well enough
to suggest a fix? I'd guess that just initializing the variable either
at point of declaration or in an else {) clause of the 'if (has_force)'
conditional would suffice, but presumably you need to handle
all the possible data types...

thanks
-- PMM

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

end of thread, other threads:[~2014-05-20 11:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-17 23:58 [Qemu-devel] qapi-commands.py generates code that uses uninitialized variables Peter Maydell
2014-03-18  9:32 ` Markus Armbruster
2014-03-20 19:21   ` Michael Roth
2014-03-26 14:34     ` Markus Armbruster
2014-03-28 14:19     ` Peter Maydell
2014-04-11  1:40       ` Eric Blake
2014-04-11  7:27         ` Peter Maydell
2014-04-11  7:48           ` Fam Zheng
2014-04-11 13:11           ` Eric Blake
2014-04-11 13:27             ` Peter Maydell
2014-04-11 14:01     ` Laszlo Ersek
2014-05-20 11:46     ` Peter Maydell

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).