From ad7a0e2111aaf599466153097e4c8eebf476244d Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Wed, 30 Nov 2011 15:08:32 +0000 Subject: Merged 0005-Handle-endianness-correctly.patch by Matt Kern. On big endian machines, pb_dec_fixed32 and pb_dec_fixed64 were incorrectly overwriting the result value even if reading failed. git-svn-id: https://svn.kapsi.fi/jpa/nanopb@1022 e3a754e5-d11d-0410-8d38-ebb782a927b9 --- pb_decode.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'pb_decode.c') diff --git a/pb_decode.c b/pb_decode.c index baa622d..3992ab8 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -474,8 +474,10 @@ bool checkreturn pb_dec_fixed32(pb_istream_t *stream, const pb_field_t *field, v #ifdef __BIG_ENDIAN__ uint8_t bytes[4] = {0}; bool status = pb_read(stream, bytes, 4); - uint8_t bebytes[4] = {bytes[3], bytes[2], bytes[1], bytes[0]}; - memcpy(dest, bebytes, 4); + if (status) { + uint8_t bebytes[4] = {bytes[3], bytes[2], bytes[1], bytes[0]}; + memcpy(dest, bebytes, 4); + } return status; #else return pb_read(stream, (uint8_t*)dest, 4); @@ -487,9 +489,11 @@ bool checkreturn pb_dec_fixed64(pb_istream_t *stream, const pb_field_t *field, v #ifdef __BIG_ENDIAN__ uint8_t bytes[8] = {0}; bool status = pb_read(stream, bytes, 8); - uint8_t bebytes[8] = {bytes[7], bytes[6], bytes[5], bytes[4], - bytes[3], bytes[2], bytes[1], bytes[0]}; - memcpy(dest, bebytes, 8); + if (status) { + uint8_t bebytes[8] = {bytes[7], bytes[6], bytes[5], bytes[4], + bytes[3], bytes[2], bytes[1], bytes[0]}; + memcpy(dest, bebytes, 8); + } return status; #else return pb_read(stream, (uint8_t*)dest, 8); -- cgit 1.2.3-korg