Skip to contentSkip to conversation

monitor: fix maybe-uninitialized

PATCH In review Paolo Bonzini 2 participants 2 messages Dec 11, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 monitor: fix maybe-uninitialized

From: Marc-André Lureau <[email protected]>

../monitor/misc.c: In function ‘mon_get_cpu_sync’:
/home/elmarco/src/qq/include/sysemu/hw_accel.h:22:9: error: ‘cpu’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

   22 |         kvm_cpu_synchronize_state(cpu);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../monitor/misc.c:397:15: note: ‘cpu’ was declared here
397 | CPUState *cpu;
| ^~~

---
 monitor/misc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
monitor/misc.c +2 -1
index 3baa15f..a74cff3 100644
@@ -394,7 +394,7 @@ int monitor_set_cpu(int cpu_index)
 /* Callers must hold BQL. */
 static CPUState *mon_get_cpu_sync(bool synchronize)
 {
-    CPUState *cpu;
+    CPUState *cpu = NULL;
 
     if (cur_mon->mon_cpu_path) {
         cpu = (CPUState *) object_resolve_path_type(cur_mon->mon_cpu_path,
@@ -411,6 +411,7 @@ static CPUState *mon_get_cpu_sync(bool synchronize)
         monitor_set_cpu(first_cpu->cpu_index);
         cpu = first_cpu;
     }
+    assert(cpu != NULL);
     if (synchronize) {
         cpu_synchronize_state(cpu);
     }
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Paolo Bonzini

From: Marc-André Lureau <[email protected]>

../monitor/misc.c: In function ‘mon_get_cpu_sync’:
/home/elmarco/src/qq/include/sysemu/hw_accel.h:22:9: error: ‘cpu’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

   22 |         kvm_cpu_synchronize_state(cpu);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../monitor/misc.c:397:15: note: ‘cpu’ was declared here
397 | CPUState *cpu;
| ^~~

---
 monitor/misc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
monitor/misc.c +1 -1
index 3baa15f..a74cff3 100644
@@ -394,7 +394,7 @@ int monitor_set_cpu(int cpu_index)
 /* Callers must hold BQL. */
 static CPUState *mon_get_cpu_sync(bool synchronize)
 {
-    CPUState *cpu;
+    CPUState *cpu = NULL;
 
     if (cur_mon->mon_cpu_path) {
         cpu = (CPUState *) object_resolve_path_type(cur_mon->mon_cpu_path,

monitor/misc.c static CPUState *mon_get_cpu_sync(bool synchronize) · line 417

Quoted 7 lines
monitor/misc.c +1 -0
@@ -411,6 +411,7 @@ static CPUState *mon_get_cpu_sync(bool synchronize)
         monitor_set_cpu(first_cpu->cpu_index);
         cpu = first_cpu;
     }
+    assert(cpu != NULL);
     if (synchronize) {
         cpu_synchronize_state(cpu);
     }