]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Ensure we have more siblings than cores
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 16 Sep 2021 19:21:08 +0000 (14:21 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 16 Sep 2021 19:24:31 +0000 (14:24 -0500)
src/lib/util/hw.c

index 8a8e3cb636c2bcb5bf86806976192061ece46d10..dcc87e4d5f5cf5ba6ff1724125215bb21210150d 100644 (file)
@@ -90,10 +90,20 @@ uint32_t fr_hw_num_cores_active(void)
                fclose(cpu);
        }
 
+#ifdef __clang_analyzer__
        /*
         *      Prevent clang scanner from warning about divide by zero
         */
-       if ((tsibs == 0) || (lcores == 0)) return 1;
+       if ((tsibs / lcores) == 0) return 1;
+#neidf
+
+       /*
+        *      Catch Linux weirdness.
+        *
+        *      You'd think this'd be enough to quite clang scan,
+        *      but it's not.
+        */
+       if (unlikely((tsibs == 0) || (lcores == 0) || (lcores > tsibs))) return 1;
 
        return lcores / (tsibs / lcores);
 }