]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpu-topo: fix unused stack var 'cpu2' reported by coverity
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 17 Mar 2025 10:01:33 +0000 (11:01 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 17 Mar 2025 13:53:36 +0000 (14:53 +0100)
Coverity has reported that cpu2 seems sometimes unused in
cpu_fixup_topology():

*** CID 1593776:  Code maintainability issues  (UNUSED_VALUE)
/src/cpu_topo.c: 690 in cpu_fixup_topology()
684                             continue;
685
686                     if (ha_cpu_topo[cpu].cl_gid != curr_id) {
687                             if (curr_id >= 0 && cl_cpu <= 2)
688                                     small_cl++;
689                             cl_cpu = 0;
>>>     CID 1593776:  Code maintainability issues  (UNUSED_VALUE)
>>>     Assigning value from "cpu" to "cpu2" here, but that stored value is overwritten before it can be used.
690                             cpu2 = cpu;
691                             curr_id = ha_cpu_topo[cpu].cl_gid;
692                     }
693                     cl_cpu++;
694             }
695

That's it. 'cpu2' automatic/stack variable is used only in for() loop scopes to
save cpus ID in which we are interested in. In the loop pointed by coverity
this variable is not used for further processing within the loop's scope.
Then it is always reinitialized to 0 in the another following loops.

This fixes GitHUb issue #2895.

src/cpu_topo.c

index 7e07b4781a45c873dec17669562599fee73cf917..009a11a3f1f3abd380b6abe62e8eb13cc3316c75 100644 (file)
@@ -676,7 +676,7 @@ void cpu_fixup_topology(void)
 
        curr_id = -1;
        cl_cpu = small_cl = 0;
-       for (cpu = cpu2 = 0; cpu <= cpu_topo_lastcpu; cpu++) {
+       for (cpu = 0; cpu <= cpu_topo_lastcpu; cpu++) {
                if (ha_cpu_topo[cpu].cl_gid < 0)
                        continue;
 
@@ -687,7 +687,6 @@ void cpu_fixup_topology(void)
                        if (curr_id >= 0 && cl_cpu <= 2)
                                small_cl++;
                        cl_cpu = 0;
-                       cpu2 = cpu;
                        curr_id = ha_cpu_topo[cpu].cl_gid;
                }
                cl_cpu++;