diff options
author | Christian Ulmann <christianulmann@gmail.com> | 2025-06-06 11:24:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-06 11:24:46 +0200 |
commit | 052d5889f871f792def285c92bd91182d07789cd (patch) | |
tree | 260334dd1e36a450f41d597db0bbbc428bc49dd6 /llvm/lib/Support/Unix/Threading.inc | |
parent | 7d4464599f2072154adf724c83aa812b538fd669 (diff) | |
download | llvm-052d5889f871f792def285c92bd91182d07789cd.zip llvm-052d5889f871f792def285c92bd91182d07789cd.tar.gz llvm-052d5889f871f792def285c92bd91182d07789cd.tar.bz2 |
[Support] Properly zero initialize CPU set when querying affinity (#142924)
This commit resolves a potential issue of working with uninitialized
memory when querying the CPU's affinity. The man page of
`sched_getaffinity` does not guarantee that the memory will be fully
overwritten, so this change should ensure that issues are avoided.
Diffstat (limited to 'llvm/lib/Support/Unix/Threading.inc')
-rw-r--r-- | llvm/lib/Support/Unix/Threading.inc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc index 742660d..562971a 100644 --- a/llvm/lib/Support/Unix/Threading.inc +++ b/llvm/lib/Support/Unix/Threading.inc @@ -318,6 +318,7 @@ static int computeHostNumHardwareThreads() { return CPU_COUNT(&mask); #elif defined(__linux__) cpu_set_t Set; + CPU_ZERO(&Set); if (sched_getaffinity(0, sizeof(Set), &Set) == 0) return CPU_COUNT(&Set); #endif |