From 2a5c77df73b721d05e2a1331b79caa5a3a0c4969 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 8 Nov 2014 10:21:12 +0100 Subject: demux_mkv: fix undefined shifts Found by clang sanitizer. Casting unsigned integers to signed integers with same size has implementation defined behavior (it's even allowed to crash), but it seems reasonable to expect that reasonable implementations do a complement of 2 "conversion". --- demux/ebml.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'demux/ebml.c') diff --git a/demux/ebml.c b/demux/ebml.c index 7e7765e425..d94aed5f64 100644 --- a/demux/ebml.c +++ b/demux/ebml.c @@ -173,7 +173,7 @@ uint64_t ebml_read_uint(stream_t *s) */ int64_t ebml_read_int(stream_t *s) { - int64_t value = 0; + uint64_t value = 0; uint64_t len; int l; @@ -189,7 +189,7 @@ int64_t ebml_read_int(stream_t *s) while (len--) value = (value << 8) | stream_read_char(s); - return value; + return (int64_t)value; // assume complement of 2 } /* @@ -328,12 +328,12 @@ static uint64_t ebml_parse_uint(uint8_t *data, int length) static int64_t ebml_parse_sint(uint8_t *data, int length) { assert(length >=1 && length <= 8); - int64_t r = 0; + uint64_t r = 0; if (*data & 0x80) r = -1; while (length--) r = (r << 8) | *data++; - return r; + return (int64_t)r; // assume complement of 2 } static double ebml_parse_float(uint8_t *data, int length) -- cgit v1.2.3