diff options
author | Ludovic Henry <luhenry@microsoft.com> | 2019-04-05 14:07:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-05 14:07:57 -0700 |
commit | 98d2b480ff9fc207f568ed2ac8dcbcb7c9d6a719 (patch) | |
tree | ccb796867c463792012596bc5bbd18197bad68bf /src | |
parent | 5b9db5fcd995b52fda09aff38ae42e75f48f8dfa (diff) | |
download | coreclr-98d2b480ff9fc207f568ed2ac8dcbcb7c9d6a719.tar.gz coreclr-98d2b480ff9fc207f568ed2ac8dcbcb7c9d6a719.tar.bz2 coreclr-98d2b480ff9fc207f568ed2ac8dcbcb7c9d6a719.zip |
Fix rounding to UINT32_MAX (#23764)
In case you would have UINT32_MAX - 1 CPUs, you would round up to return UINT32_MAX CPUs.
Diffstat (limited to 'src')
-rw-r--r-- | src/gc/unix/cgroup.cpp | 15 | ||||
-rw-r--r-- | src/pal/src/misc/cgroup.cpp | 13 |
2 files changed, 7 insertions, 21 deletions
diff --git a/src/gc/unix/cgroup.cpp b/src/gc/unix/cgroup.cpp index 10b9b869ca..f81f14deb4 100644 --- a/src/gc/unix/cgroup.cpp +++ b/src/gc/unix/cgroup.cpp @@ -118,17 +118,10 @@ public: *val = 1; return true; } - - cpu_count = (double) quota / period; - if (cpu_count < UINT32_MAX - 1) - { - // round up - *val = (uint32_t)(cpu_count + 0.999999999); - } - else - { - *val = UINT32_MAX; - } + + // Calculate cpu count based on quota and round it up + cpu_count = (double) quota / period + 0.999999999; + *val = (cpu_count < UINT32_MAX) ? (uint32_t)cpu_count : UINT32_MAX; return true; } diff --git a/src/pal/src/misc/cgroup.cpp b/src/pal/src/misc/cgroup.cpp index 97b2cb287c..2018df4eda 100644 --- a/src/pal/src/misc/cgroup.cpp +++ b/src/pal/src/misc/cgroup.cpp @@ -107,16 +107,9 @@ public: return true; } - cpu_count = (double) quota / period; - if (cpu_count < UINT_MAX - 1) - { - // round up - *val = (UINT)(cpu_count + 0.999999999); - } - else - { - *val = UINT_MAX; - } + // Calculate cpu count based on quota and round it up + cpu_count = (double) quota / period + 0.999999999; + *val = (cpu_count < UINT_MAX) ? (UINT)cpu_count : UINT_MAX; return true; } |