"Ronald S. Bultje" <[email protected]> writes: > From: Uoti Urpala <[email protected]> > > The output type of the AV_RL32/AV_RB32 macros was signed int. The > resulting overflow broke at least some ASF streams with large > timestamps. Fix by adding a cast to uint32_t. > > Signed-off-by: Ronald S. Bultje <[email protected]> > --- > libavutil/intreadwrite.h | 16 ++++++++-------- > 1 files changed, 8 insertions(+), 8 deletions(-) > > diff --git a/libavutil/intreadwrite.h b/libavutil/intreadwrite.h > index c8489f1..0bacdb8 100644 > --- a/libavutil/intreadwrite.h > +++ b/libavutil/intreadwrite.h > @@ -230,10 +230,10 @@ union unaligned_16 { uint16_t l; } > __attribute__((packed)) av_alias; > > #ifndef AV_RB32 > # define AV_RB32(x) \ > - ((((const uint8_t*)(x))[0] << 24) | \ > - (((const uint8_t*)(x))[1] << 16) | \ > - (((const uint8_t*)(x))[2] << 8) | \ > - ((const uint8_t*)(x))[3]) > + ((uint32_t)(((const uint8_t*)(x))[0] << 24) |\ > + (((const uint8_t*)(x))[1] << 16) |\ > + (((const uint8_t*)(x))[2] << 8) |\ > + ((const uint8_t*)(x))[3])
The first shift is undefined if bit 7 of that byte is set. The cast has to be done before the shift. The remaining values don't need a cast as they will then be first implicitly promoted to int, then shifted a safe amount, the converted to unsigned by the bitwise or operation. Also, it is still ugly. Please align the backslashes and leave some space between the last character on a line and the backslash. -- Måns Rullgård [email protected] _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
