Left shifting a negative integer is undefined, yet often needed. Therefore add a macro that internally uses multiplication by powers of two to make it clear that a shift is intended.
Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@gmail.com> --- I don't insist on this macro. I only added it so that one can easily see that shifting was intended. I initially wanted to use "FFLS", but eventually chose FFLSHIFT because it is self-explanatory. libavutil/common.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavutil/common.h b/libavutil/common.h index af35397eb9..93c5dd0af7 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -60,6 +60,14 @@ /* Backwards compat. */ #define FF_CEIL_RSHIFT AV_CEIL_RSHIFT +/** + * Left shift macro designed to tackle the undefinedness + * of left-shifting negative numbers. + * + * Note: Still undefined if the multiplication overflows. + */ +#define FFLSHIFT(a,b) ((a) * (1 << (b))) + #define FFUDIV(a,b) (((a)>0 ?(a):(a)-(b)+1) / (b)) #define FFUMOD(a,b) ((a)-(b)*FFUDIV(a,b)) -- 2.20.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".