[FFmpeg-devel] [PATCH 2/3] avutil/common: assert that bit position in av_zero_extend is valid
James Almer
jamrial at gmail.com
Tue Jun 11 21:52:31 EEST 2024
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavutil/common.h | 3 +++
libavutil/x86/intmath.h | 5 ++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/libavutil/common.h b/libavutil/common.h
index acd041fb67..65448d47d3 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -296,6 +296,9 @@ static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
*/
static av_always_inline av_const unsigned av_zero_extend_c(unsigned a, unsigned p)
{
+#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
+ if (p > 31) abort();
+#endif
return a & ((1U << p) - 1);
}
diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h
index 821a06ab66..de6da72129 100644
--- a/libavutil/x86/intmath.h
+++ b/libavutil/x86/intmath.h
@@ -90,8 +90,11 @@ static av_always_inline av_const int ff_ctzll_x86(long long v)
#define av_zero_extend av_zero_extend_bmi2
static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsigned p)
{
+#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
+ if (p > 31) abort();
+#endif
if (av_builtin_constant_p(p))
- return a & ((1 << p) - 1);
+ return a & ((1U << p) - 1);
else {
unsigned x;
__asm__ ("bzhi %2, %1, %0 \n\t" : "=r"(x) : "rm"(a), "r"(p));
--
2.45.2
More information about the ffmpeg-devel
mailing list