[FFmpeg-devel] [PATCH 2/5] lavu/common.h: Fix UB in av_clip_intp2_c()

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Thu May 30 01:24:24 EEST 2024


Tomas Härdin:
>  static av_always_inline av_const int av_clip_intp2_c(int a, int p)
>  {
> -    if (((unsigned)a + (1 << p)) & ~((2 << p) - 1))
> +    if (((unsigned)a + (1U << p)) & ~((2U << p) - 1))
>          return (a >> 31) ^ ((1 << p) - 1);
>      else
>          return a;

This will support p == 30 (but not 31); but the first change is not UB
in this range.

- Andreas



More information about the ffmpeg-devel mailing list