qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Stefan Weil <sw@weilnetz.de>
Cc: qemu-trivial <qemu-trivial@nongnu.org>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] migration: Fix compiler warning ('caps' may be used uninitialized)
Date: Mon, 30 Sep 2013 00:13:52 +0400	[thread overview]
Message-ID: <52488A00.6000405@msgid.tls.msk.ru> (raw)
In-Reply-To: <1380469272-19230-1-git-send-email-sw@weilnetz.de>

29.09.2013 19:41, Stefan Weil wrote:
> The QEMU buildbot default_i386_debian_6_0 shows this warning:
>
>    CC    migration.o
> migration.c: In function 'qmp_query_migrate_capabilities':
> migration.c:149: warning:
>   'caps' may be used uninitialized in this function

Gah, how disgusting.  The code is correct, yet gcc complains
needlessly...

> While changing this code, I also replaced g_malloc0
> by the type safe g_new0.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> Buildbot URL:
> http://buildbot.b1-systems.de/qemu/builders/default_i386_debian_6_0/builds/775/steps/compile/logs/stdio
>
>   migration.c |   12 +++++-------
>   1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/migration.c b/migration.c
> index 200d404..8dcb6ce 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -145,17 +145,15 @@ uint64_t migrate_max_downtime(void)
>
>   MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
>   {
> -    MigrationCapabilityStatusList *head = NULL;
> -    MigrationCapabilityStatusList *caps;
> +    MigrationCapabilityStatusList *head =
> +        g_new0(MigrationCapabilityStatusList, 1);
> +    MigrationCapabilityStatusList *caps = head;
>       MigrationState *s = migrate_get_current();
>       int i;
>
>       for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
> -        if (head == NULL) {
> -            head = g_malloc0(sizeof(*caps));
> -            caps = head;
> -        } else {
> -            caps->next = g_malloc0(sizeof(*caps));
> +        if (i > 0) {
> +            caps->next = g_new0(MigrationCapabilityStatusList, i);
>               caps = caps->next;
>           }

But this assumes that MIGRATION_CAPABILITY_MAX > 0 ! ;)
Ie, that there's at least one entry (head) in the list.
Do we care?

Previous code was more natural, so to say...

I'd just initialize `caps' to the same NULL as `head'
initially...  Or maybe change for() into do..while()..
Dunno, somehow I don't like the new code much, either ;)

Thanks,

/mjt

  reply	other threads:[~2013-09-29 20:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-29 15:41 [Qemu-devel] [PATCH] migration: Fix compiler warning ('caps' may be used uninitialized) Stefan Weil
2013-09-29 20:13 ` Michael Tokarev [this message]
2013-09-29 20:33   ` [Qemu-devel] [Qemu-trivial] " Stefan Weil
2013-09-30  9:59     ` Markus Armbruster
2013-09-30 20:53       ` Stefan Weil
2013-10-01  8:07         ` Markus Armbruster
2013-10-02 19:02         ` Michael Tokarev
2013-10-02 20:24           ` Stefan Weil
2013-10-03  8:13             ` Paolo Bonzini
2013-10-05  9:15               ` Michael Tokarev
2013-10-05  9:19                 ` Michael Tokarev
2013-10-05  9:36                   ` Stefan Weil
2013-10-01 11:39 ` [Qemu-devel] " Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52488A00.6000405@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).