From a9b707460b20b5e2d78dfe0d91cfd9ecfbddc5ee Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Sun, 29 Sep 2024 23:00:00 +0100 Subject: [PATCH] garouter/gaChannel.c use of unintialized or incorrect variable This resolution assumes that all records and values of ch->gcr_type are expected to be one of the 3 cases in the switch. The bug it on the first iteration it is possible 'tot' and 'clear' is just not initializaed and on a subsequent iteration it is possible it ot setup to the previous interation values. SonarCloud garouter/gaChannel.c:385:3rd function call argument is an uninitialized value https://sonarcloud.io/project/issues?open=AZJB17fFNGfDNup0RkoE&id=dlmiles_magic --- garouter/gaChannel.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/garouter/gaChannel.c b/garouter/gaChannel.c index 718631d9..a7b9a584 100644 --- a/garouter/gaChannel.c +++ b/garouter/gaChannel.c @@ -381,11 +381,17 @@ gaChannelStats(list) tot = &gaTotRiverCross; clear = &gaClearRiverCross; break; + default: /* otherwise tot and clear is not intialized */ + tot = NULL; + clear = NULL; + break; + } + if(tot && clear) { + gaPinStats(ch->gcr_tPins, ch->gcr_length, tot, clear); + gaPinStats(ch->gcr_bPins, ch->gcr_length, tot, clear); + gaPinStats(ch->gcr_lPins, ch->gcr_width, tot, clear); + gaPinStats(ch->gcr_rPins, ch->gcr_width, tot, clear); } - gaPinStats(ch->gcr_tPins, ch->gcr_length, tot, clear); - gaPinStats(ch->gcr_bPins, ch->gcr_length, tot, clear); - gaPinStats(ch->gcr_lPins, ch->gcr_width, tot, clear); - gaPinStats(ch->gcr_rPins, ch->gcr_width, tot, clear); } numTot = gaTotRiverCross + gaTotNormCross;