[33/40] sim/ppc: Initialize reg and control_nr

Message ID d69dd39bab75b71b071bee5323165282011eb27f.1666258361.git.research_trasio@irq.a4lg.com
State Committed
Headers
Series sim+gdb: Suppress warnings if built with Clang (big batch 1) |

Commit Message

Tsukasa OI Oct. 20, 2022, 9:32 a.m. UTC
  GCC generates a warning if a variable may be used uninitialized on some
cases ("-Wmaybe-uninitialized").  Despite that GCC will not cause a build
failure even when "--enable-werror" is specified, it would be nice to get
rid of it.

This commit initializes variables "reg" and "control_nr" when declared.
---
 sim/ppc/hw_ide.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Mike Frysinger Oct. 23, 2022, 3:14 p.m. UTC | #1
On 20 Oct 2022 09:32, Tsukasa OI wrote:
> GCC generates a warning if a variable may be used uninitialized on some
> cases ("-Wmaybe-uninitialized").  Despite that GCC will not cause a build
> failure even when "--enable-werror" is specified, it would be nice to get
> rid of it.
> 
> This commit initializes variables "reg" and "control_nr" when declared.
> ---
>  sim/ppc/hw_ide.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> --- a/sim/ppc/hw_ide.c
> +++ b/sim/ppc/hw_ide.c
> @@ -729,8 +729,8 @@ hw_ide_io_read_buffer(device *me,
>  		      unsigned_word cia)
>  {
>    hw_ide_device *ide = (hw_ide_device *)device_data(me);
> -  int control_nr;
> -  int reg;
> +  int control_nr = 0;
> +  int reg = 0;
>    ide_controller *controller;
>  
>    /* find the interface */
> @@ -783,8 +783,8 @@ hw_ide_io_write_buffer(device *me,
>  		       unsigned_word cia)
>  {
>    hw_ide_device *ide = (hw_ide_device *)device_data(me);
> -  int control_nr;
> -  int reg;
> +  int control_nr = 0;
> +  int reg = 0;
>    ide_controller *controller;
>  
>    /* find the interface */

afaict, this is a false positive.  these two vars are initialized by the
decode_address call, and if it's unable to, it calls device_error which
is supposed to be marked NORETURN.

what if we change decode_address to initialize both output variables and
leave a comment there explaining why.
-mike
  

Patch

diff --git a/sim/ppc/hw_ide.c b/sim/ppc/hw_ide.c
index af61eeccab6..b4ac8e99204 100644
--- a/sim/ppc/hw_ide.c
+++ b/sim/ppc/hw_ide.c
@@ -729,8 +729,8 @@  hw_ide_io_read_buffer(device *me,
 		      unsigned_word cia)
 {
   hw_ide_device *ide = (hw_ide_device *)device_data(me);
-  int control_nr;
-  int reg;
+  int control_nr = 0;
+  int reg = 0;
   ide_controller *controller;
 
   /* find the interface */
@@ -783,8 +783,8 @@  hw_ide_io_write_buffer(device *me,
 		       unsigned_word cia)
 {
   hw_ide_device *ide = (hw_ide_device *)device_data(me);
-  int control_nr;
-  int reg;
+  int control_nr = 0;
+  int reg = 0;
   ide_controller *controller;
 
   /* find the interface */