From 342b588e3b470d778d752cd7a63c7565c09a09ee Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 11 Apr 2024 09:20:44 +0200 Subject: [PATCH] avoid some static analysis errors Modify the code to avoid some false positives reported by the clang and gcc static analyzers. --- regress.c | 2 +- sourcestats.c | 4 ++-- tempcomp.c | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/regress.c b/regress.c index e767e2f..1c86457 100644 --- a/regress.c +++ b/regress.c @@ -377,7 +377,7 @@ find_ordered_entry_with_flags(double *x, int n, int index, char *flags) r = v; do { while (l < v && x[l] < piv) l++; - while (x[r] > piv) r--; + while (r > 0 && x[r] > piv) r--; if (r <= l) break; EXCH(x[l], x[r]); l++; diff --git a/sourcestats.c b/sourcestats.c index ce326e9..fcc501a 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -549,9 +549,9 @@ SST_DoNewRegression(SST_Stats inst) sd_weight += (peer_distances[i] - min_distance) / sd; weights[i] = SQUARE(sd_weight); } - } - correct_asymmetry(inst, times_back, offsets); + correct_asymmetry(inst, times_back, offsets); + } inst->regression_ok = RGR_FindBestRegression(times_back + inst->runs_samples, offsets + inst->runs_samples, weights, diff --git a/tempcomp.c b/tempcomp.c index a468e33..4c36367 100644 --- a/tempcomp.c +++ b/tempcomp.c @@ -66,10 +66,9 @@ get_tempcomp(double temp) return k0 + (temp - T0) * k1 + (temp - T0) * (temp - T0) * k2; /* Otherwise interpolate/extrapolate between two nearest points */ - - for (i = 1; i < ARR_GetSize(points); i++) { - p2 = (struct Point *)ARR_GetElement(points, i); - if (p2->temp >= temp) + for (i = 1; ; i++) { + p2 = ARR_GetElement(points, i); + if (p2->temp >= temp || i + 1 >= ARR_GetSize(points)) break; } p1 = p2 - 1;