[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.
This commit is contained in:
Christian Ulmann 2025-06-06 11:24:46 +02:00 committed by GitHub
parent 7d4464599f
commit 052d5889f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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