diff options
author | Jeffrey Walton <noloader@gmail.com> | 2021-03-11 14:28:01 -0500 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2021-03-11 14:28:01 -0500 |
commit | babff262c5514fdf048ceced2b4083ce21db0c0a (patch) | |
tree | d118a18ee210949068a5e2d5354909fbab00476c | |
parent | 575c42b6f4c1c024033e16040777d7409bd48023 (diff) | |
download | cryptopp-git-babff262c5514fdf048ceced2b4083ce21db0c0a.tar.gz |
Avoid second call to sysctlbyname on Apple M1
-rw-r--r-- | cpu.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -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")
|