[19/40] sim/m32r: Initialize "list" variable

Message ID 6559cc9db4127924fbd8a753b6674c72f466ca24.1666258361.git.research_trasio@irq.a4lg.com
State Committed
Commit 45f8296e6965ff4e2ca855e995149add6352645d
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
  The variable "list" is only initialized when arg1 > 0 and when arg1 == 0,
an uninitialized value is passed to translate_endian_h2t function.

Although this behavior is harmless, this commit adds initialization to avoid
a GCC warning ("-Wmaybe-uninitialized").
---
 sim/m32r/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Mike Frysinger Oct. 23, 2022, 2:50 p.m. UTC | #1
On 20 Oct 2022 09:32, Tsukasa OI wrote:
> The variable "list" is only initialized when arg1 > 0 and when arg1 == 0,
> an uninitialized value is passed to translate_endian_h2t function.
> 
> Although this behavior is harmless, this commit adds initialization to avoid
> a GCC warning ("-Wmaybe-uninitialized").

as you said, the code as-is is fine, but setting it to NULL to make the warning
go away sounds fine to me
-mike
  

Patch

diff --git a/sim/m32r/traps.c b/sim/m32r/traps.c
index 267d54881da..12a87b4a697 100644
--- a/sim/m32r/traps.c
+++ b/sim/m32r/traps.c
@@ -547,7 +547,7 @@  m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 	  case TARGET_LINUX_SYS_getgroups32:
 	  case TARGET_LINUX_SYS_getgroups:
 	    {
-	      gid_t *list;
+	      gid_t *list = NULL;
 
 	      if (arg1 > 0)
 		list = (gid_t *) malloc (arg1 * sizeof(gid_t));