[FFmpeg-cvslog] qt-faststart: Avoid unintentionally sign extending BE_32
Martin Storsjö
git at videolan.org
Mon Mar 3 22:50:34 CET 2014
ffmpeg | branch: release/2.2 | Martin Storsjö <martin at martin.st> | Fri Feb 28 12:19:49 2014 +0200| [9841617b7f862fcf24ad05eda865a3f323ee0dd0] | committer: Reinhard Tartler
qt-faststart: Avoid unintentionally sign extending BE_32
Without this cast, the BE_32() expression is sign extended when
assigned to an uint64_t, since the uint8_t|uint8_t expression
is promoted to an int.
Also avoid undefined behaviour when left shifting an uint8_t
by 24 by casting it to an uint32_t explicitly before shifting.
Based on a patch by Michael Niedermayer.
Signed-off-by: Martin Storsjö <martin at martin.st>
(cherry picked from commit ea7f79f93796d68559a495be824b6bbd94dfe5f6)
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9841617b7f862fcf24ad05eda865a3f323ee0dd0
---
tools/qt-faststart.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index 792c272..3a0139f 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -41,10 +41,10 @@
#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
-#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
- (((uint8_t*)(x))[1] << 16) | \
- (((uint8_t*)(x))[2] << 8) | \
- ((uint8_t*)(x))[3])
+#define BE_32(x) (((uint32_t)(((uint8_t*)(x))[0]) << 24) | \
+ (((uint8_t*)(x))[1] << 16) | \
+ (((uint8_t*)(x))[2] << 8) | \
+ ((uint8_t*)(x))[3])
#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \
((uint64_t)(((uint8_t*)(x))[1]) << 48) | \
@@ -123,7 +123,7 @@ int main(int argc, char *argv[])
if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
break;
}
- atom_size = (uint32_t) BE_32(&atom_bytes[0]);
+ atom_size = BE_32(&atom_bytes[0]);
atom_type = BE_32(&atom_bytes[4]);
/* keep ftyp atom */
More information about the ffmpeg-cvslog
mailing list