[FFmpeg-devel] [PATCH] lavu/common: Fix AV_CEIL_RSHIFT for unsigned LHS
Frank Plowman
post at frankplowman.com
Sun Oct 6 01:38:05 EEST 2024
The first branch of this ternary expression was intended to avoid
having two shift operations in the case the RHS is not known at
compile time. It only works if the LHS has a signed type however,
otherwise the result is invalid.
We could alternatively have different versions of AV_CEIL_RSHIFT for
different sizes of operand, then cast the LHS to the relevant signed
type.
Signed-off-by: Frank Plowman <post at frankplowman.com>
---
libavutil/common.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavutil/common.h b/libavutil/common.h
index 3b830daf30..ec38752b64 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -57,8 +57,7 @@
/* assume b>0 */
#define ROUNDED_DIV(a,b) (((a)>=0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
/* Fast a/(1<<b) rounded toward +inf. Assume a>=0 and b>=0 */
-#define AV_CEIL_RSHIFT(a,b) (!av_builtin_constant_p(b) ? -((-(a)) >> (b)) \
- : ((a) + (1<<(b)) - 1) >> (b))
+#define AV_CEIL_RSHIFT(a,b) (((a) + (1<<(b)) - 1) >> (b))
/* Backwards compat. */
#define FF_CEIL_RSHIFT AV_CEIL_RSHIFT
--
2.46.2
More information about the ffmpeg-devel
mailing list