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

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


Tomas Härdin:
>   */
>  static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a)
>  {
> -    if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (int32_t)((a>>63) ^ 0x7FFFFFFF);
> -    else                                         return (int32_t)a;
> +    if ((a+UINT64_C(0x80000000)) & ~UINT64_C(0xFFFFFFFF)) return (int32_t)((a>>63) ^ 0x7FFFFFFF);
> +    else                                                  return (int32_t)a;

IMO (uint64_t)a + 0x80000000 is more readable. (Maybe it would even be
good to use >> 32 instead of ~UINT64_C(0xFFFFFFFF)?)

- Andreas



More information about the ffmpeg-devel mailing list