]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Check for zero tsibs and zero lcores before *sigh*
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 16 Sep 2021 23:52:17 +0000 (18:52 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 16 Sep 2021 23:52:17 +0000 (18:52 -0500)
src/lib/util/hw.c

index cbd3d166d79f1b0a681dafd714d2fa45b2265d2e..d83677a926e97926db3dbdd117e6a18a8768b262 100644 (file)
@@ -69,7 +69,7 @@ size_t fr_hw_cache_line_size(void)
 
 uint32_t fr_hw_num_cores_active(void)
 {
-       uint32_t lcores = 0, tsibs = 0;
+       uint32_t lcores = 0, tsibs = 0;
 
        char buff[32];
        char path[64];
@@ -90,13 +90,6 @@ uint32_t fr_hw_num_cores_active(void)
                fclose(cpu);
        }
 
-#ifdef __clang_analyzer__
-       /*
-        *      Prevent clang scanner from warning about divide by zero
-        */
-       if ((tsibs / lcores) == 0) return 1;
-#endif
-
        /*
         *      Catch Linux weirdness.
         *
@@ -105,6 +98,13 @@ uint32_t fr_hw_num_cores_active(void)
         */
        if (unlikely((tsibs == 0) || (lcores == 0) || (lcores > tsibs))) return 1;
 
+#ifdef __clang_analyzer__
+       /*
+        *      Prevent clang scanner from warning about divide by zero
+        */
+       if ((tsibs / lcores) == 0) return 1;
+#endif
+
        return lcores / (tsibs / lcores);
 }
 #else