From: Arran Cudbard-Bell Date: Thu, 16 Sep 2021 23:52:17 +0000 (-0500) Subject: Check for zero tsibs and zero lcores before *sigh* X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51f13f149f41e6b158ed041b4fd02c39d548d7ca;p=thirdparty%2Ffreeradius-server.git Check for zero tsibs and zero lcores before *sigh* --- diff --git a/src/lib/util/hw.c b/src/lib/util/hw.c index cbd3d166d7..d83677a926 100644 --- a/src/lib/util/hw.c +++ b/src/lib/util/hw.c @@ -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