diff --git a/ndk_compat/cpu-features.c b/ndk_compat/cpu-features.c index 27ff7bbd..c7d11be9 100644 --- a/ndk_compat/cpu-features.c +++ b/ndk_compat/cpu-features.c @@ -27,7 +27,11 @@ static uint32_t g_cpuIdArm; #endif static void set_cpu_mask_bit(uint32_t index, uint32_t* cpu_mask) { - *cpu_mask |= 1UL << index; + // cpu_mask is a 32-bit mask; a larger index would shift past its width + // (shifting by >= the operand width is undefined behavior). The range path + // in parse_cpu_mask bounds indices the same way. + if (index >= 32) return; + *cpu_mask |= (uint32_t)1 << index; } // Examples of valid inputs: "31", "4-31"