From 9df4e7c70e0c5e8e62ffcc30382614a7e300c79f Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 21 Nov 2014 05:17:19 +0100 Subject: [PATCH] stream: fix endian swapping In addition to the messed-up expression, the endianness was also inverted. The code reads big endian by default. It "worked" by coincidence, but for little endian, codepoints outside of latin1 were broken. The broken expression was found by Coverity. --- stream/stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stream/stream.c b/stream/stream.c index 862d7fe252..2a851e82ec 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -861,8 +861,8 @@ static uint16_t stream_read_word_endian(stream_t *s, bool big_endian) { unsigned int y = stream_read_char(s); y = (y << 8) | stream_read_char(s); - if (big_endian) - y = (y >> 8) | ((y << 8) & 0xFF); + if (!big_endian) + y = ((y >> 8) & 0xFF) | (y << 8); return y; }