]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim/cgen: initialize variable at creation in engine_run_n
authorAndrew Burgess <aburgess@redhat.com>
Mon, 24 Oct 2022 15:55:07 +0000 (16:55 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 27 Oct 2022 15:52:07 +0000 (16:52 +0100)
Zero initialize engine_fns entirely at creation, then override those
fields we intend to use, rather than zero just initializing the unused
fields later on.

There should be no user visible changes after this commit.

sim/common/cgen-run.c

index a9a493c01b9fe7f5348f6e95884b281c752d80c8..b6400a69c13e8994fd36d1d7175140477c69e9cb 100644 (file)
@@ -229,7 +229,9 @@ static void
 engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast_p)
 {
   int i;
-  ENGINE_FN *engine_fns[MAX_NR_PROCESSORS];
+  /* Ensure that engine_fns is fully initialized, this silences a compiler
+     warning when engine_fns is used below.  */
+  ENGINE_FN *engine_fns[MAX_NR_PROCESSORS] = {};
 
   SIM_ASSERT (nr_cpus <= MAX_NR_PROCESSORS);
   SIM_ASSERT (next_cpu_nr >= 0 && next_cpu_nr < nr_cpus);
@@ -242,11 +244,6 @@ engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast
       prime_cpu (cpu, max_insns);
     }
 
-  /* Ensure the remaining engine_fns slots are initialized, this silences a
-     compiler warning when engine_fns is used below.  */
-  for (i = nr_cpus; i < MAX_NR_PROCESSORS; ++i)
-    engine_fns[i] = NULL;
-
   while (1)
     {
       SIM_ENGINE_PREFIX_HOOK (sd);