aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-06-13 21:43:40 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-06-13 21:43:40 +0300
commit7e1059628c1d67f96c00781cf2f57c915feadde1 (patch)
tree8a75bbfea278c0a7be6ab8edcc102792187ed373
parent5af2c97ecd71af46cc45baefb7a7041b5b904efc (diff)
Fix non-constant initializer errors with some compilers.
Fixes issue #13. Thanks to Kevin Worth for reporting.
-rw-r--r--pb_decode.c19
-rw-r--r--pb_encode.c17
2 files changed, 28 insertions, 8 deletions
diff --git a/pb_decode.c b/pb_decode.c
index fd234884..eace906f 100644
--- a/pb_decode.c
+++ b/pb_decode.c
@@ -476,8 +476,11 @@ bool checkreturn pb_dec_fixed32(pb_istream_t *stream, const pb_field_t *field, v
uint8_t bytes[4] = {0};
bool status = pb_read(stream, bytes, 4);
if (status) {
- uint8_t bebytes[4] = {bytes[3], bytes[2], bytes[1], bytes[0]};
- memcpy(dest, bebytes, 4);
+ uint8_t *d = (uint8_t*)dest;
+ d[0] = bytes[3];
+ d[1] = bytes[2];
+ d[2] = bytes[1];
+ d[3] = bytes[0];
}
return status;
#else
@@ -492,9 +495,15 @@ bool checkreturn pb_dec_fixed64(pb_istream_t *stream, const pb_field_t *field, v
uint8_t bytes[8] = {0};
bool status = pb_read(stream, bytes, 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);
+ uint8_t *d = (uint8_t*)dest;
+ d[0] = bytes[7];
+ d[1] = bytes[6];
+ d[2] = bytes[5];
+ d[3] = bytes[4];
+ d[4] = bytes[3];
+ d[5] = bytes[2];
+ d[6] = bytes[1];
+ d[7] = bytes[0];
}
return status;
#else
diff --git a/pb_encode.c b/pb_encode.c
index 18173735..c6cccf21 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -236,7 +236,11 @@ bool checkreturn pb_encode_fixed32(pb_ostream_t *stream, const void *value)
{
#ifdef __BIG_ENDIAN__
uint8_t *bytes = value;
- uint8_t lebytes[4] = {bytes[3], bytes[2], bytes[1], bytes[0]};
+ uint8_t lebytes[4];
+ lebytes[0] = bytes[3];
+ lebytes[1] = bytes[2];
+ lebytes[2] = bytes[1];
+ lebytes[3] = bytes[0];
return pb_write(stream, lebytes, 4);
#else
return pb_write(stream, (uint8_t*)value, 4);
@@ -247,8 +251,15 @@ bool checkreturn pb_encode_fixed64(pb_ostream_t *stream, const void *value)
{
#ifdef __BIG_ENDIAN__
uint8_t *bytes[8] = value;
- uint8_t lebytes[8] = {bytes[7], bytes[6], bytes[5], bytes[4],
- bytes[3], bytes[2], bytes[1], bytes[0]};
+ uint8_t lebytes[8];
+ lebytes[0] = bytes[7];
+ lebytes[1] = bytes[6];
+ lebytes[2] = bytes[5];
+ lebytes[3] = bytes[4];
+ lebytes[4] = bytes[3];
+ lebytes[5] = bytes[2];
+ lebytes[6] = bytes[1];
+ lebytes[7] = bytes[0];
return pb_write(stream, lebytes, 8);
#else
return pb_write(stream, (uint8_t*)value, 8);