diff options
author | Petteri Aimonen <jpa@npb.mail.kapsi.fi> | 2011-11-30 15:08:32 +0000 |
---|---|---|
committer | Petteri Aimonen <jpa@npb.mail.kapsi.fi> | 2011-11-30 15:08:32 +0000 |
commit | ad7a0e2111aaf599466153097e4c8eebf476244d (patch) | |
tree | 0c8e2ac3ab2b3238eecb0b0a9f839ce31b49075e | |
parent | 2a80ff2bd596b61ad8bca7b174f12a7dd99efaf5 (diff) |
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
-rw-r--r-- | pb_decode.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pb_decode.c b/pb_decode.c index baa622d3..3992ab86 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); |