* This is an optimization for the varint decoding. */
static bool checkreturn pb_readbyte(pb_istream_t *stream, uint8_t *buf)
{
- if (!stream->bytes_left)
+ if (stream->bytes_left == 0)
PB_RETURN_ERROR(stream, "end-of-stream");
#ifndef PB_BUFFER_ONLY
if (!pb_readbyte(stream, &byte))
return false;
- if (!(byte & 0x80))
+ if ((byte & 0x80) == 0)
{
/* Quick case, 1 byte value */
result = byte;
{
return true;
}
- pb_field_next(iter);
+ (void)pb_field_next(iter);
} while (iter->field_index != start);
return false;
if (!pb_make_string_substream(stream, &substream))
return false;
- while (substream.bytes_left && *size < iter->pos->array_size)
+ while (substream.bytes_left > 0 && *size < iter->pos->array_size)
{
void *pItem = (uint8_t*)iter->pData + iter->pos->data_size * (*size);
if (!func(&substream, iter->pos, pItem))
pb_extension_t *extension = *(pb_extension_t* const *)iter->pData;
size_t pos = stream->bytes_left;
- while (extension && pos == stream->bytes_left)
+ while (extension != NULL && pos == stream->bytes_left)
{
bool status;
if (extension->type->decode)
do {
if (PB_LTYPE(iter->pos->type) == PB_LTYPE_EXTENSION)
return true;
- pb_field_next(iter);
+ (void)pb_field_next(iter);
} while (iter->field_index != start);
return false;
bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
{
- uint8_t fields_seen[(PB_MAX_REQUIRED_FIELDS + 7) / 8] = {0}; /* Used to check for required fields */
+ uint8_t fields_seen[(PB_MAX_REQUIRED_FIELDS + 7) / 8] = {0, 0, 0, 0, 0, 0, 0, 0};
uint32_t extension_range_start = 0;
pb_field_iterator_t iter;
} while (pb_field_next(&iter));
/* Fixup if last field was also required. */
- if (PB_HTYPE(last_type) == PB_HTYPE_REQUIRED && iter.pos->tag)
+ if (PB_HTYPE(last_type) == PB_HTYPE_REQUIRED && iter.pos->tag != 0)
req_field_count++;
/* Check the whole bytes */
{
uint64_t zigzagged;
if (value < 0)
- zigzagged = (uint64_t)(~(value << 1));
+ zigzagged = ~((uint64_t)value << 1);
else
- zigzagged = (uint64_t)(value << 1);
+ zigzagged = (uint64_t)value << 1;
return pb_encode_varint(stream, zigzagged);
}
bool checkreturn pb_encode_tag(pb_ostream_t *stream, pb_wire_type_t wiretype, uint32_t field_number)
{
- uint64_t tag = wiretype | (field_number << 3);
+ uint64_t tag = ((uint64_t)field_number << 3) | wiretype;
return pb_encode_varint(stream, tag);
}
--- /dev/null
+# Check the nanopb core using splint
+
+Import('env')
+
+p = env.WhereIs('splint')
+
+if p:
+ env.Command('pb_decode.splint', '$NANOPB/pb_decode.c',
+ 'splint -f splint/splint.rc $SOURCE 2> $TARGET')
+
+ env.Command('pb_encode.splint', '$NANOPB/pb_encode.c',
+ 'splint -f splint/splint.rc $SOURCE 2> $TARGET')
+