From: Valentine Krasnobaeva Date: Mon, 17 Mar 2025 10:01:33 +0000 (+0100) Subject: MINOR: cpu-topo: fix unused stack var 'cpu2' reported by coverity X-Git-Tag: v3.2-dev8~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=557f62593fe3a569819959e735344c0fe1cdb910;p=thirdparty%2Fhaproxy.git MINOR: cpu-topo: fix unused stack var 'cpu2' reported by coverity 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. --- diff --git a/src/cpu_topo.c b/src/cpu_topo.c index 7e07b4781..009a11a3f 100644 --- a/src/cpu_topo.c +++ b/src/cpu_topo.c @@ -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++;