mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-29 23:42:12 +08:00
protobuf-c/protobuf-c.c: add explicit casts in parsing functions for
better compatibility with 8- and 16-bit platforms (integrate fixes from #47)
This commit is contained in:
parent
5b3ac9ca97
commit
ffb1c2462a
@ -1723,18 +1723,18 @@ count_packed_elements (ProtobufCType type,
|
|||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
parse_uint32 (unsigned len, const uint8_t *data)
|
parse_uint32 (unsigned len, const uint8_t *data)
|
||||||
{
|
{
|
||||||
unsigned rv = data[0] & 0x7f;
|
uint32_t rv = data[0] & 0x7f;
|
||||||
if (len > 1)
|
if (len > 1)
|
||||||
{
|
{
|
||||||
rv |= ((data[1] & 0x7f) << 7);
|
rv |= ((uint32_t)(data[1] & 0x7f) << 7);
|
||||||
if (len > 2)
|
if (len > 2)
|
||||||
{
|
{
|
||||||
rv |= ((data[2] & 0x7f) << 14);
|
rv |= ((uint32_t)(data[2] & 0x7f) << 14);
|
||||||
if (len > 3)
|
if (len > 3)
|
||||||
{
|
{
|
||||||
rv |= ((data[3] & 0x7f) << 21);
|
rv |= ((uint32_t)(data[3] & 0x7f) << 21);
|
||||||
if (len > 4)
|
if (len > 4)
|
||||||
rv |= (data[4] << 28);
|
rv |= ((uint32_t)(data[4]) << 28);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1761,7 +1761,8 @@ parse_fixed_uint32 (const uint8_t *data)
|
|||||||
memcpy (&t, data, 4);
|
memcpy (&t, data, 4);
|
||||||
return t;
|
return t;
|
||||||
#else
|
#else
|
||||||
return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
|
return data[0] | ((uint32_t)(data[1]) << 8) | ((uint32_t)(data[2]) << 16)
|
||||||
|
| ((uint32_t)(data[3]) << 24);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static uint64_t
|
static uint64_t
|
||||||
@ -1771,10 +1772,10 @@ parse_uint64 (unsigned len, const uint8_t *data)
|
|||||||
uint64_t rv;
|
uint64_t rv;
|
||||||
if (len < 5)
|
if (len < 5)
|
||||||
return parse_uint32 (len, data);
|
return parse_uint32 (len, data);
|
||||||
rv = ((data[0] & 0x7f))
|
rv = ((uint64_t)(data[0] & 0x7f))
|
||||||
| ((data[1] & 0x7f)<<7)
|
| ((uint64_t)(data[1] & 0x7f)<<7)
|
||||||
| ((data[2] & 0x7f)<<14)
|
| ((uint64_t)(data[2] & 0x7f)<<14)
|
||||||
| ((data[3] & 0x7f)<<21);
|
| ((uint64_t)(data[3] & 0x7f)<<21);
|
||||||
shift = 28;
|
shift = 28;
|
||||||
for (i = 4; i < len; i++)
|
for (i = 4; i < len; i++)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user