]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
avoid some static analysis errors
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 11 Apr 2024 07:20:44 +0000 (09:20 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 11 Apr 2024 08:31:02 +0000 (10:31 +0200)
Modify the code to avoid some false positives reported by the clang and
gcc static analyzers.

regress.c
sourcestats.c
tempcomp.c

index e767e2f1a2d8a0fdb5864e2c565afd3189efbfdf..1c864573077e8d9f0734e610c7fb5c96c3197413 100644 (file)
--- 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++;
index ce326e9494609c9a5303640f00e6aa6a48673986..fcc501a22f14d9c4bc92e583e79f225414f06842 100644 (file)
@@ -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,
index a468e338eb95f977ba2b2c6809e4f03335e608c5..4c363676fd606af462eccb76307364a6b52463a0 100644 (file)
@@ -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;