diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2012-09-03 17:35:14 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2012-09-03 17:35:14 +0300 |
commit | b214de4e1e53f14354db36b8f199db6177a63744 (patch) | |
tree | 5b45b98c14a59d075d3ab939efc13ecb1ab9f8e5 | |
parent | be78e3b4d0ff9839817b0eeef5d3e75056b53af1 (diff) |
Enable -Wconversion for core and fix the warnings.
This should help avoid issue 33 in the future.
-rw-r--r-- | pb.h | 9 | ||||
-rw-r--r-- | pb_decode.c | 8 | ||||
-rw-r--r-- | pb_encode.c | 10 | ||||
-rw-r--r-- | pb_encode.h | 2 | ||||
-rw-r--r-- | tests/Makefile | 2 |
5 files changed, 17 insertions, 14 deletions
@@ -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. diff --git a/pb_decode.c b/pb_decode.c index 65db511c..86dec4b7 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -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; } diff --git a/pb_encode.c b/pb_encode.c index a8873828..5d1965d1 100644 --- a/pb_encode.c +++ b/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) { diff --git a/pb_encode.h b/pb_encode.h index 59ec554b..af6cc3c5 100644 --- a/pb_encode.h +++ b/pb_encode.h @@ -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. */ diff --git a/tests/Makefile b/tests/Makefile index e4c67c59..9b02817f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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 |