Skip to contentSkip to conversation

hw/openrisc/openrisc_sim: Avoid using uninitialised variable 'entry'

PATCH In review Peter Maydell 2 participants 4 messages Aug 5, 2013 – Aug 20, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/openrisc/openrisc_sim: Avoid using uninitialised variable 'entry'

clang warns that cpu_openrisc_load_kernel() can use 'entry' uninitialized:

hw/openrisc/openrisc_sim.c:69:9: error: variable 'entry' is used

      uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
    if (kernel_filename && !qtest_enabled()) {
        ^~~~~~~~~~~~~~~
hw/openrisc/openrisc_sim.c:91:19: note: uninitialized use occurs here
    cpu->env.pc = entry;
                  ^~~~~

Fix this by not attempting to change the CPU's starting PC unless we actually loaded a kernel.

---
 hw/openrisc/openrisc_sim.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +2 -2
index a08f27c..4595fa9 100644
@@ -86,9 +86,9 @@ static void cpu_openrisc_load_kernel(ram_addr_t ram_size,
                     kernel_filename);
             exit(1);
         }
-    }
 
-    cpu->env.pc = entry;
+        cpu->env.pc = entry;
+    }
 }
 
 static void openrisc_sim_init(QEMUMachineInitArgs *args)
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw

Hi Peter,

Quoted 24 lines · Peter Maydell

clang warns that cpu_openrisc_load_kernel() can use 'entry' uninitialized:

hw/openrisc/openrisc_sim.c:69:9: error: variable 'entry' is used

      uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
    if (kernel_filename && !qtest_enabled()) {
        ^~~~~~~~~~~~~~~
hw/openrisc/openrisc_sim.c:91:19: note: uninitialized use occurs here
    cpu->env.pc = entry;
                  ^~~~~

Fix this by not attempting to change the CPU's starting PC unless we actually loaded a kernel.

---
 hw/openrisc/openrisc_sim.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +0 -0
index a08f27c..4595fa9 100644
@@ -86,9 +86,9 @@ static void cpu_openrisc_load_kernel(ram_addr_t ram_size,
                     kernel_filename);

hw/openrisc/openrisc_sim.c static void cpu_openrisc_load_kernel(ram_addr_t ram_size, · line 94

Quoted 10 lines
hw/openrisc/openrisc_sim.c +2 -2
             exit(1);
         }
-    }
 
-    cpu->env.pc = entry;
+        cpu->env.pc = entry;
+    }
 }
 
 static void openrisc_sim_init(QEMUMachineInitArgs *args)

Thank you for using clang test it.

Quoted 3 lines

--
1.7.9.5

Regards,
Jia

#2 lore raw
In reply to Peter Maydell

Ping for qemu-trivial now 1.7 is open.

thanks
-- PMM

Quoted 38 lines · Peter Maydell

clang warns that cpu_openrisc_load_kernel() can use 'entry' uninitialized:

hw/openrisc/openrisc_sim.c:69:9: error: variable 'entry' is used

      uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
    if (kernel_filename && !qtest_enabled()) {
        ^~~~~~~~~~~~~~~
hw/openrisc/openrisc_sim.c:91:19: note: uninitialized use occurs here
    cpu->env.pc = entry;
                  ^~~~~

Fix this by not attempting to change the CPU's starting PC unless we actually loaded a kernel.

---
 hw/openrisc/openrisc_sim.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +2 -3
index a08f27c..4595fa9 100644
@@ -86,9 +86,9 @@ static void cpu_openrisc_load_kernel(ram_addr_t ram_size,
                     kernel_filename);
             exit(1);
         }
-    }
 
-    cpu->env.pc = entry;
+        cpu->env.pc = entry;
+    }
 }
 
 static void openrisc_sim_init(QEMUMachineInitArgs *args)
--

1.7.9.5

#3 lore raw

Hi Peter,

Quoted 1 line · Peter Maydell

Ping for qemu-trivial now 1.7 is open.

Thank you, I'll send a PULL very soon.

Quoted 38 lines

thanks
-- PMM

Quoted 33 lines · Peter Maydell

clang warns that cpu_openrisc_load_kernel() can use 'entry' uninitialized:

hw/openrisc/openrisc_sim.c:69:9: error: variable 'entry' is used

      uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
    if (kernel_filename && !qtest_enabled()) {
        ^~~~~~~~~~~~~~~
hw/openrisc/openrisc_sim.c:91:19: note: uninitialized use occurs here
    cpu->env.pc = entry;
                  ^~~~~

Fix this by not attempting to change the CPU's starting PC unless we actually loaded a kernel.

---
 hw/openrisc/openrisc_sim.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +2 -2
index a08f27c..4595fa9 100644
@@ -86,9 +86,9 @@ static void cpu_openrisc_load_kernel(ram_addr_t ram_size,
                     kernel_filename);
             exit(1);
         }
-    }
 
-    cpu->env.pc = entry;
+        cpu->env.pc = entry;
+    }
 }
 
Quoted 5 lines
Quoted 5 lines
hw/openrisc/openrisc_sim.c +0 -1
 static void openrisc_sim_init(QEMUMachineInitArgs *args)
--

1.7.9.5

Regards,
Jia