diff mbox series

[FFmpeg-devel] avutil/integer: ignore the upper bits of AVInteger in av_i2int()

Message ID 20221021130047.1169-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] avutil/integer: ignore the upper bits of AVInteger in av_i2int() | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer Oct. 21, 2022, 1 p.m. UTC
The function is meant to return the least significant 64 bits after all.
Should fix undefined behavior (left shift of negative values) as reported by ubsan.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/integer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/integer.c b/libavutil/integer.c
index b709c6d487..4ba33bcbc5 100644
--- a/libavutil/integer.c
+++ b/libavutil/integer.c
@@ -159,9 +159,9 @@  AVInteger av_int2i(int64_t a){
 
 int64_t av_i2int(AVInteger a){
     int i;
-    int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
+    int64_t out = a.v[AV_INTEGER_SIZE - 5];
 
-    for(i= AV_INTEGER_SIZE-2; i>=0; i--){
+    for (i = AV_INTEGER_SIZE - 6; i >= 0; i--) {
         out = (out<<16) + a.v[i];
     }
     return out;