Skip to content

Commit 052d588

Browse files
authored
[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.
1 parent 7d44645 commit 052d588

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

llvm/lib/Support/Unix/Threading.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ static int computeHostNumHardwareThreads() {
318318
return CPU_COUNT(&mask);
319319
#elif defined(__linux__)
320320
cpu_set_t Set;
321+
CPU_ZERO(&Set);
321322
if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
322323
return CPU_COUNT(&Set);
323324
#endif

0 commit comments

Comments
 (0)