Fix warnings with -Wcast-qual. Add test for C++ compile.
Update issue 27 Status: FixedInGit
This commit is contained in:
@@ -612,6 +612,7 @@ bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field
|
|||||||
{
|
{
|
||||||
bool status;
|
bool status;
|
||||||
pb_istream_t substream;
|
pb_istream_t substream;
|
||||||
|
const pb_field_t* submsg_fields = (const pb_field_t*)field->ptr;
|
||||||
|
|
||||||
if (!pb_make_string_substream(stream, &substream))
|
if (!pb_make_string_substream(stream, &substream))
|
||||||
return false;
|
return false;
|
||||||
@@ -619,7 +620,13 @@ bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field
|
|||||||
if (field->ptr == NULL)
|
if (field->ptr == NULL)
|
||||||
PB_RETURN_ERROR(stream, "invalid field descriptor");
|
PB_RETURN_ERROR(stream, "invalid field descriptor");
|
||||||
|
|
||||||
status = pb_decode_noinit(&substream, (pb_field_t*)field->ptr, dest);
|
/* New array entries need to be initialized, while required and optional
|
||||||
|
* submessages have already been initialized in the top-level pb_decode. */
|
||||||
|
if (PB_HTYPE(field->type) == PB_HTYPE_ARRAY)
|
||||||
|
status = pb_decode(&substream, submsg_fields, dest);
|
||||||
|
else
|
||||||
|
status = pb_decode_noinit(&substream, submsg_fields, dest);
|
||||||
|
|
||||||
pb_close_string_substream(stream, &substream);
|
pb_close_string_substream(stream, &substream);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
28
pb_encode.c
28
pb_encode.c
@@ -168,7 +168,7 @@ bool checkreturn pb_encode(pb_ostream_t *stream, const pb_field_t fields[], cons
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PB_HTYPE_OPTIONAL:
|
case PB_HTYPE_OPTIONAL:
|
||||||
if (*(bool*)pSize)
|
if (*(const bool*)pSize)
|
||||||
{
|
{
|
||||||
if (!pb_encode_tag_for_field(stream, field))
|
if (!pb_encode_tag_for_field(stream, field))
|
||||||
return false;
|
return false;
|
||||||
@@ -179,13 +179,13 @@ bool checkreturn pb_encode(pb_ostream_t *stream, const pb_field_t fields[], cons
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PB_HTYPE_ARRAY:
|
case PB_HTYPE_ARRAY:
|
||||||
if (!encode_array(stream, field, pData, *(size_t*)pSize, func))
|
if (!encode_array(stream, field, pData, *(const size_t*)pSize, func))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PB_HTYPE_CALLBACK:
|
case PB_HTYPE_CALLBACK:
|
||||||
{
|
{
|
||||||
pb_callback_t *callback = (pb_callback_t*)pData;
|
const pb_callback_t *callback = (const pb_callback_t*)pData;
|
||||||
if (callback->funcs.encode != NULL)
|
if (callback->funcs.encode != NULL)
|
||||||
{
|
{
|
||||||
if (!callback->funcs.encode(stream, field, callback->arg))
|
if (!callback->funcs.encode(stream, field, callback->arg))
|
||||||
@@ -243,7 +243,7 @@ bool checkreturn pb_encode_fixed32(pb_ostream_t *stream, const void *value)
|
|||||||
lebytes[3] = bytes[0];
|
lebytes[3] = bytes[0];
|
||||||
return pb_write(stream, lebytes, 4);
|
return pb_write(stream, lebytes, 4);
|
||||||
#else
|
#else
|
||||||
return pb_write(stream, (uint8_t*)value, 4);
|
return pb_write(stream, (const uint8_t*)value, 4);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ bool checkreturn pb_encode_fixed64(pb_ostream_t *stream, const void *value)
|
|||||||
lebytes[7] = bytes[0];
|
lebytes[7] = bytes[0];
|
||||||
return pb_write(stream, lebytes, 8);
|
return pb_write(stream, lebytes, 8);
|
||||||
#else
|
#else
|
||||||
return pb_write(stream, (uint8_t*)value, 8);
|
return pb_write(stream, (const uint8_t*)value, 8);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,10 +358,10 @@ bool checkreturn pb_enc_varint(pb_ostream_t *stream, const pb_field_t *field, co
|
|||||||
|
|
||||||
switch (field->data_size)
|
switch (field->data_size)
|
||||||
{
|
{
|
||||||
case 1: value = *(uint8_t*)src; break;
|
case 1: value = *(const uint8_t*)src; break;
|
||||||
case 2: value = *(uint16_t*)src; break;
|
case 2: value = *(const uint16_t*)src; break;
|
||||||
case 4: value = *(uint32_t*)src; break;
|
case 4: value = *(const uint32_t*)src; break;
|
||||||
case 8: value = *(uint64_t*)src; break;
|
case 8: value = *(const uint64_t*)src; break;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,8 +374,8 @@ bool checkreturn pb_enc_svarint(pb_ostream_t *stream, const pb_field_t *field, c
|
|||||||
|
|
||||||
switch (field->data_size)
|
switch (field->data_size)
|
||||||
{
|
{
|
||||||
case 4: value = *(int32_t*)src; break;
|
case 4: value = *(const int32_t*)src; break;
|
||||||
case 8: value = *(int64_t*)src; break;
|
case 8: value = *(const int64_t*)src; break;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,7 +396,7 @@ bool checkreturn pb_enc_fixed32(pb_ostream_t *stream, const pb_field_t *field, c
|
|||||||
|
|
||||||
bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src)
|
bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src)
|
||||||
{
|
{
|
||||||
pb_bytes_array_t *bytes = (pb_bytes_array_t*)src;
|
const pb_bytes_array_t *bytes = (const pb_bytes_array_t*)src;
|
||||||
UNUSED(field);
|
UNUSED(field);
|
||||||
return pb_encode_string(stream, bytes->bytes, bytes->size);
|
return pb_encode_string(stream, bytes->bytes, bytes->size);
|
||||||
}
|
}
|
||||||
@@ -404,7 +404,7 @@ bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, con
|
|||||||
bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_t *field, const void *src)
|
bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_t *field, const void *src)
|
||||||
{
|
{
|
||||||
UNUSED(field);
|
UNUSED(field);
|
||||||
return pb_encode_string(stream, (uint8_t*)src, strlen((char*)src));
|
return pb_encode_string(stream, (const uint8_t*)src, strlen((const char*)src));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_t *field, const void *src)
|
bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_t *field, const void *src)
|
||||||
@@ -412,6 +412,6 @@ bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_t *field
|
|||||||
if (field->ptr == NULL)
|
if (field->ptr == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return pb_encode_submessage(stream, (pb_field_t*)field->ptr, src);
|
return pb_encode_submessage(stream, (const pb_field_t*)field->ptr, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
TESTS=test_decode1 test_encode1 decode_unittests encode_unittests test_no_messages
|
||||||
|
|
||||||
# More strict checks for the core part of nanopb
|
# More strict checks for the core part of nanopb
|
||||||
CFLAGS_CORE=-pedantic -Wextra
|
CFLAGS_CORE=-pedantic -Wextra -Wcast-qual -Wlogical-op
|
||||||
|
|
||||||
all: breakpoints $(TESTS) run_unittests
|
all: breakpoints $(TESTS) run_unittests
|
||||||
|
|
||||||
@@ -20,6 +20,12 @@ pb_encode.o: ../pb_encode.c $(DEPS)
|
|||||||
pb_decode.o: ../pb_decode.c $(DEPS)
|
pb_decode.o: ../pb_decode.c $(DEPS)
|
||||||
$(CC) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
|
$(CC) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
|
||||||
|
|
||||||
|
pb_encode.cxx.o: ../pb_encode.c $(DEPS)
|
||||||
|
$(CXX) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
|
||||||
|
pb_decode.cxx.o: ../pb_decode.c $(DEPS)
|
||||||
|
$(CXX) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
|
||||||
|
|
||||||
|
test_cxxcompile: pb_encode.cxx.o pb_decode.cxx.o
|
||||||
test_decode1: test_decode1.o pb_decode.o person.pb.o
|
test_decode1: test_decode1.o pb_decode.o person.pb.o
|
||||||
test_decode2: test_decode2.o pb_decode.o person.pb.o
|
test_decode2: test_decode2.o pb_decode.o person.pb.o
|
||||||
test_decode3: test_decode3.o pb_decode.o alltypes.pb.o
|
test_decode3: test_decode3.o pb_decode.o alltypes.pb.o
|
||||||
@@ -46,7 +52,7 @@ coverage: run_unittests
|
|||||||
gcov pb_encode.gcda
|
gcov pb_encode.gcda
|
||||||
gcov pb_decode.gcda
|
gcov pb_decode.gcda
|
||||||
|
|
||||||
run_unittests: decode_unittests encode_unittests test_encode1 test_encode2 test_encode3 test_decode1 test_decode2 test_decode3 test_encode_callbacks test_decode_callbacks test_missing_fields
|
run_unittests: decode_unittests encode_unittests test_cxxcompile test_encode1 test_encode2 test_encode3 test_decode1 test_decode2 test_decode3 test_encode_callbacks test_decode_callbacks test_missing_fields
|
||||||
rm -f *.gcda
|
rm -f *.gcda
|
||||||
|
|
||||||
./decode_unittests > /dev/null
|
./decode_unittests > /dev/null
|
||||||
|
|||||||
Reference in New Issue
Block a user