[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-trivial] [PATCH] migration: Fix compiler warning ('caps' may b
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-trivial] [PATCH] migration: Fix compiler warning ('caps' may be used uninitialized) |
Date: |
Tue, 01 Oct 2013 13:39:06 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130923 Thunderbird/17.0.9 |
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 <address@hidden>
> ---
>
> 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;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Qemu-trivial] [PATCH] migration: Fix compiler warning ('caps' may be used uninitialized),
Paolo Bonzini <=