summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-03-11 14:28:01 -0500
committerJeffrey Walton <noloader@gmail.com>2021-03-11 14:28:01 -0500
commitbabff262c5514fdf048ceced2b4083ce21db0c0a (patch)
treed118a18ee210949068a5e2d5354909fbab00476c
parent575c42b6f4c1c024033e16040777d7409bd48023 (diff)
downloadcryptopp-git-babff262c5514fdf048ceced2b4083ce21db0c0a.tar.gz
Avoid second call to sysctlbyname on Apple M1
-rw-r--r--cpu.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/cpu.cpp b/cpu.cpp
index f8a4900e..e57556a5 100644
--- a/cpu.cpp
+++ b/cpu.cpp
@@ -219,17 +219,16 @@ public:
{
// M1 machine?
std::string brand;
- size_t size = 0;
+ size_t size = 32;
- if (sysctlbyname("machdep.cpu.brand_string", NULL, &size, NULL, 0) == 0 && size > 0)
+ // Supply an oversized buffer, and avoid
+ // an extra call to sysctlbyname.
+ brand.resize(size);
+ if (sysctlbyname("machdep.cpu.brand_string", &brand[0], &size, NULL, 0) == 0 && size > 0)
{
+ if (brand[size-1] == '\0')
+ size--;
brand.resize(size);
- if (sysctlbyname("machdep.cpu.brand_string", &brand[0], &size, NULL, 0) == 0 && size > 0)
- {
- if (brand[size-1] == '\0')
- size--;
- brand.resize(size);
- }
}
if (brand == "Apple M1")