1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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@martin.st>
This commit is contained in:
Martin Storsjö 2014-02-28 12:19:49 +02:00
parent bb95334c34
commit ea7f79f937

View File

@ -41,7 +41,7 @@
#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) #define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ #define BE_32(x) (((uint32_t)(((uint8_t*)(x))[0]) << 24) | \
(((uint8_t*)(x))[1] << 16) | \ (((uint8_t*)(x))[1] << 16) | \
(((uint8_t*)(x))[2] << 8) | \ (((uint8_t*)(x))[2] << 8) | \
((uint8_t*)(x))[3]) ((uint8_t*)(x))[3])
@ -123,7 +123,7 @@ int main(int argc, char *argv[])
if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
break; break;
} }
atom_size = (uint32_t) BE_32(&atom_bytes[0]); atom_size = BE_32(&atom_bytes[0]);
atom_type = BE_32(&atom_bytes[4]); atom_type = BE_32(&atom_bytes[4]);
/* keep ftyp atom */ /* keep ftyp atom */