Enable -Wconversion for core and fix the warnings.
This should help avoid issue 33 in the future.
This commit is contained in:
9
pb.h
9
pb.h
@@ -75,6 +75,7 @@ typedef enum {
|
||||
|
||||
/* Number of declared LTYPES */
|
||||
PB_LTYPES_COUNT = 7,
|
||||
PB_LTYPE_MASK = 0x0F,
|
||||
|
||||
/******************
|
||||
* Modifier flags *
|
||||
@@ -95,11 +96,13 @@ typedef enum {
|
||||
* data_offset points to pb_callback_t structure.
|
||||
* LTYPE should be 0 (it is ignored, but sometimes
|
||||
* used to speculatively index an array). */
|
||||
PB_HTYPE_CALLBACK = 0x30
|
||||
PB_HTYPE_CALLBACK = 0x30,
|
||||
|
||||
PB_HTYPE_MASK = 0xF0
|
||||
} pb_packed pb_type_t;
|
||||
|
||||
#define PB_HTYPE(x) ((x) & 0xF0)
|
||||
#define PB_LTYPE(x) ((x) & 0x0F)
|
||||
#define PB_HTYPE(x) ((x) & PB_HTYPE_MASK)
|
||||
#define PB_LTYPE(x) ((x) & PB_LTYPE_MASK)
|
||||
|
||||
/* This structure is used in auto-generated constants
|
||||
* to specify struct fields.
|
||||
|
||||
@@ -83,7 +83,7 @@ static bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest)
|
||||
bool checkreturn pb_decode_varint(pb_istream_t *stream, uint64_t *dest)
|
||||
{
|
||||
uint8_t byte;
|
||||
uint8_t bitpos = 0;
|
||||
int bitpos = 0;
|
||||
*dest = 0;
|
||||
|
||||
while (bitpos < 64 && pb_read(stream, &byte, 1))
|
||||
@@ -447,7 +447,7 @@ bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[
|
||||
if (PB_HTYPE(iter.current->type) == PB_HTYPE_REQUIRED
|
||||
&& iter.required_field_index < PB_MAX_REQUIRED_FIELDS)
|
||||
{
|
||||
fields_seen[iter.required_field_index >> 3] |= 1 << (iter.required_field_index & 7);
|
||||
fields_seen[iter.required_field_index >> 3] |= (uint8_t)(1 << (iter.required_field_index & 7));
|
||||
}
|
||||
|
||||
if (!decode_field(stream, wire_type, &iter))
|
||||
@@ -483,9 +483,9 @@ bool pb_decode_svarint(pb_istream_t *stream, int64_t *dest)
|
||||
return false;
|
||||
|
||||
if (value & 1)
|
||||
*dest = ~(value >> 1);
|
||||
*dest = (int64_t)(~(value >> 1));
|
||||
else
|
||||
*dest = value >> 1;
|
||||
*dest = (int64_t)(value >> 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
10
pb_encode.c
10
pb_encode.c
@@ -205,7 +205,7 @@ bool checkreturn pb_encode(pb_ostream_t *stream, const pb_field_t fields[], cons
|
||||
bool checkreturn pb_encode_varint(pb_ostream_t *stream, uint64_t value)
|
||||
{
|
||||
uint8_t buffer[10];
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
if (value == 0)
|
||||
return pb_write(stream, (uint8_t*)&value, 1);
|
||||
@@ -225,9 +225,9 @@ bool checkreturn pb_encode_svarint(pb_ostream_t *stream, int64_t value)
|
||||
{
|
||||
uint64_t zigzagged;
|
||||
if (value < 0)
|
||||
zigzagged = ~(value << 1);
|
||||
zigzagged = (uint64_t)(~(value << 1));
|
||||
else
|
||||
zigzagged = value << 1;
|
||||
zigzagged = (uint64_t)(value << 1);
|
||||
|
||||
return pb_encode_varint(stream, zigzagged);
|
||||
}
|
||||
@@ -266,7 +266,7 @@ bool checkreturn pb_encode_fixed64(pb_ostream_t *stream, const void *value)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool checkreturn pb_encode_tag(pb_ostream_t *stream, pb_wire_type_t wiretype, int field_number)
|
||||
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);
|
||||
return pb_encode_varint(stream, tag);
|
||||
@@ -370,7 +370,7 @@ bool checkreturn pb_enc_varint(pb_ostream_t *stream, const pb_field_t *field, co
|
||||
|
||||
bool checkreturn pb_enc_svarint(pb_ostream_t *stream, const pb_field_t *field, const void *src)
|
||||
{
|
||||
uint64_t value = 0;
|
||||
int64_t value = 0;
|
||||
|
||||
switch (field->data_size)
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ bool pb_encode_tag_for_field(pb_ostream_t *stream, const pb_field_t *field);
|
||||
|
||||
/* Encode field header by manually specifing wire type. You need to use this if
|
||||
* you want to write out packed arrays from a callback field. */
|
||||
bool pb_encode_tag(pb_ostream_t *stream, pb_wire_type_t wiretype, int field_number);
|
||||
bool pb_encode_tag(pb_ostream_t *stream, pb_wire_type_t wiretype, uint32_t field_number);
|
||||
|
||||
/* Encode an integer in the varint format.
|
||||
* This works for bool, enum, int32, int64, uint32 and uint64 field types. */
|
||||
|
||||
@@ -4,7 +4,7 @@ DEPS=../pb_decode.h ../pb_encode.h ../pb.h person.pb.h callbacks.pb.h unittests.
|
||||
TESTS=test_decode1 test_encode1 decode_unittests encode_unittests test_no_messages
|
||||
|
||||
# More strict checks for the core part of nanopb
|
||||
CFLAGS_CORE=-pedantic -Wextra -Wcast-qual -Wlogical-op
|
||||
CFLAGS_CORE=-pedantic -Wextra -Wcast-qual -Wlogical-op -Wconversion
|
||||
|
||||
all: breakpoints $(TESTS) run_unittests
|
||||
|
||||
|
||||
Reference in New Issue
Block a user