[FFmpeg-devel] [PATCH] compat: Fix the fallback definition of stdc_trailing_zeros
Martin Storsjö
martin at martin.st
Tue Sep 24 11:53:38 EEST 2024
While shifting "value" to left, we would iterate through all bits
of an unsigned long long, while we only expect to count through
"size * CHAR_BIT" bits.
This fixes fate with MSVC.
---
compat/stdbit/stdbit.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/compat/stdbit/stdbit.h b/compat/stdbit/stdbit.h
index b434fc2357..3197a24938 100644
--- a/compat/stdbit/stdbit.h
+++ b/compat/stdbit/stdbit.h
@@ -179,9 +179,10 @@ static inline unsigned int __stdc_trailing_zeros(unsigned long long value,
unsigned int size)
{
unsigned int zeros = size * CHAR_BIT;
+ unsigned long long mask = (1ULL << (size * CHAR_BIT)) - 1;
while (value != 0) {
- value <<= 1;
+ value = (value << 1) & mask;
zeros--;
}
--
2.39.5 (Apple Git-154)
More information about the ffmpeg-devel
mailing list