{
uint64_t temp;
bool status = pb_decode_varint(stream, &temp);
- *dest = temp;
+ *dest = (uint32_t)temp;
return status;
}
* to just assume the correct type and fail safely on corrupt message.
*/
-static bool checkreturn skip(pb_istream_t *stream, int wire_type)
+static bool checkreturn skip(pb_istream_t *stream, pb_wire_type_t wire_type)
{
switch (wire_type)
{
{
iter->start = iter->current = fields;
iter->field_index = 0;
- iter->pData = dest_struct + iter->current->data_offset;
+ iter->pData = (char*)dest_struct + iter->current->data_offset;
iter->pSize = (char*)iter->pData + iter->current->size_offset;
iter->dest_struct = dest_struct;
}
* Decode a single field *
*************************/
-static bool checkreturn decode_field(pb_istream_t *stream, int wire_type, pb_field_iterator_t *iter)
+static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iterator_t *iter)
{
pb_decoder_t func = PB_DECODERS[PB_LTYPE(iter->current->type)];
while (stream->bytes_left)
{
uint32_t temp;
- int tag, wire_type;
+ int tag;
+ pb_wire_type_t wire_type;
if (!pb_decode_varint32(stream, &temp))
{
if (stream->bytes_left == 0)
break; /* Special feature: allow 0-terminated messages. */
tag = temp >> 3;
- wire_type = temp & 7;
+ wire_type = (pb_wire_type_t)(temp & 7);
if (!pb_field_find(&iter, tag))
{
#ifdef __BIG_ENDIAN__
memcpy(dest, (char*)src + (srcsize - destsize), destsize);
#else
+ UNUSED(srcsize);
memcpy(dest, src, destsize);
#endif
}
#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
+ UNUSED(field);
return pb_read(stream, (uint8_t*)dest, 4);
#endif
}
#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
+ UNUSED(field);
return pb_read(stream, (uint8_t*)dest, 8);
#endif
}
return false;
x->size = temp;
- if (x->size > field->data_size)
+ /* Check length, noting the space taken by the size_t header. */
+ if (x->size > field->data_size - offsetof(pb_bytes_array_t, bytes))
return false;
return pb_read(stream, x->bytes, x->size);
if (!pb_decode_varint32(stream, &size))
return false;
- if (size > field->data_size - 1)
+ /* Check length, noting the null terminator */
+ if (size + 1 > field->data_size)
return false;
status = pb_read(stream, (uint8_t*)dest, size);