Fix unsafe use of CPU_ISSET_S macro. (#1357)
Don't increment mapped_idx via prefix increment within the argument of the potentially unsafe CPU_ISSET_S macro. If the macro is expanded so that the increment expression is evaluated multiple times, it will return unexpected results. While the glibc implementation of CPU_ISSET_S macro seems to be safe, the musl libc (v1.1.23) version is unsafe and will evaluate the first argument of CPU_ISSET_S three times. Co-authored-by: Christian Priebe <cp3213@ic.ac.uk>
This commit is contained in:
parent
29816f7a44
commit
ee3fafceda
@ -57,10 +57,11 @@ bool PinThreadToVacantCore(int thrIdx, int hyperthreads, int ncores, const CpuSe
|
||||
}
|
||||
|
||||
// Find index of 'cpu_idx'-th bit that equals to 1
|
||||
int mapped_idx = -1;
|
||||
int mapped_idx = 0;
|
||||
while (cpu_idx >= 0) {
|
||||
if (CPU_ISSET_S(++mapped_idx, size, procMask.get()))
|
||||
if (CPU_ISSET_S(mapped_idx, size, procMask.get()))
|
||||
--cpu_idx;
|
||||
mapped_idx++;
|
||||
}
|
||||
|
||||
CpuSet targetMask{CPU_ALLOC(ncores)};
|
||||
|
Loading…
Reference in New Issue
Block a user