Skip to content

Commit e5bb804

Browse files
committed
[Support] Properly zero initialize CPU set when querying affinity
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 54da543 commit e5bb804

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
@@ -316,6 +316,7 @@ static int computeHostNumHardwareThreads() {
316316
return CPU_COUNT(&mask);
317317
#elif defined(__linux__)
318318
cpu_set_t Set;
319+
CPU_ZERO(&Set);
319320
if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
320321
return CPU_COUNT(&Set);
321322
#endif

0 commit comments

Comments
 (0)