qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Weil <sw@weilnetz.de>
Cc: qemu-trivial <qemu-trivial@nongnu.org>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] migration: Fix compiler warning ('caps' may be used uninitialized)
Date: Tue, 01 Oct 2013 13:39:06 +0200	[thread overview]
Message-ID: <524AB45A.6050805@redhat.com> (raw)
In-Reply-To: <1380469272-19230-1-git-send-email-sw@weilnetz.de>

Il 29/09/2013 17:41, Stefan Weil ha scritto:
> 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
> 
> 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;
>          }
>          caps->value =
> 

What about

    MigrationCapabilityStatusList *head = NULL;
    MigrationCapabilityStatusList **p_tail = &head;
    MigrationState *s = migrate_get_current();
    int i;

    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
        MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
        caps->value =
            ...
        *p_next = caps;
        p_next = &caps->next;
    }

      parent reply	other threads:[~2013-10-01 11:39 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 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2013-09-29 20:33   ` 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 ` Paolo Bonzini [this message]

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=524AB45A.6050805@redhat.com \
    --to=pbonzini@redhat.com \
    --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).