From: Stefan Weil <sw@weilnetz.de>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-trivial <qemu-trivial@nongnu.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] migration: Fix compiler warning ('caps' may be used uninitialized)
Date: Wed, 02 Oct 2013 22:24:13 +0200 [thread overview]
Message-ID: <524C80ED.3020507@weilnetz.de> (raw)
In-Reply-To: <524C6DD0.9070605@msgid.tls.msk.ru>
Am 02.10.2013 21:02, schrieb Michael Tokarev:
> How about this:
>
> diff --git a/migration.c b/migration.c
> index b4f8462..6066ab4 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -146,22 +146,16 @@ uint64_t migrate_max_downtime(void)
> MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error
> **errp)
> {
> MigrationCapabilityStatusList *head = NULL;
> - MigrationCapabilityStatusList *caps;
> + MigrationCapabilityStatusList **capp = &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));
> - caps = caps->next;
> - }
> - caps->value =
> - g_malloc(sizeof(*caps->value));
> - caps->value->capability = i;
> - caps->value->state = s->enabled_capabilities[i];
> + *capp = g_malloc0(sizeof(*head));
> + (*capp)->value = g_malloc(sizeof(*head->value));
> + (*capp)->value->capability = i;
> + (*capp)->value->state = s->enabled_capabilities[i];
> + capp = &(*capp)->next;
> }
>
> return head;
>
>
> This is what I had in mind at the very beginnig, but only now tried
> to make a patch...
>
> Thanks,
>
> /mjt
> Thanks,
That's a possible solution. Paolo also sent a sketch of a similar
solution. And here are two more:
MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
{
MigrationCapabilityStatusList *head = NULL;
MigrationState *s = migrate_get_current();
MigrationCapability i = MIGRATION_CAPABILITY_MAX;
do {
MigrationCapabilityStatusList *caps =
g_new(MigrationCapabilityStatusList, 1);
i--;
caps->next = head;
caps->value = g_new(MigrationCapabilityStatus, 1);
caps->value->capability = i;
caps->value->state = s->enabled_capabilities[i];
head = caps;
} while (i > 0);
return head;
}
MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
{
MigrationCapabilityStatusList *head = NULL;
MigrationCapabilityStatusList *prev = NULL;
MigrationState *s = migrate_get_current();
MigrationCapability i;
for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
MigrationCapabilityStatusList *caps =
g_new(MigrationCapabilityStatusList, 1);
if (prev == NULL) {
head = caps;
} else {
prev->next = caps;
prev = caps;
}
caps->value = g_new(MigrationCapabilityStatus, 1);
caps->value->capability = i;
caps->value->state = s->enabled_capabilities[i];
}
return head;
}
Which one do we take? Any correct solution which fixes the compiler
warning is fine for me (although I prefer g_new instead of g_malloc as
you might have guessed). :-)
Regards,
Stefan
next prev parent reply other threads:[~2013-10-02 20:24 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 [this message]
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=524C80ED.3020507@weilnetz.de \
--to=sw@weilnetz.de \
--cc=armbru@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/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).