Skip to content
Snippets Groups Projects
Commit 99399108 authored by Petteri Aimonen's avatar Petteri Aimonen
Browse files

Fix bug with empty strings in repeated string callbacks.

Fix suggested by Henrik Carlgren. Added also unit test for the bug.

Update issue 73
Status: FixedInGit
parent 6a022985
No related branches found
No related tags found
No related merge requests found
......@@ -430,11 +430,11 @@ static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type
if (!pb_make_string_substream(stream, &substream))
return false;
while (substream.bytes_left)
do
{
if (!pCallback->funcs.decode(&substream, iter->pos, arg))
PB_RETURN_ERROR(stream, "callback failed");
}
} while (substream.bytes_left);
pb_close_string_substream(stream, &substream);
return true;
......
......@@ -11,5 +11,6 @@ message TestMessage {
repeated fixed32 fixed32value = 3;
repeated fixed64 fixed64value = 4;
optional SubMessage submsg = 5;
repeated string repeatedstring = 6;
}
......@@ -83,6 +83,8 @@ int main()
testmessage.fixed32value.arg = "fixed32value: %ld\n";
testmessage.fixed64value.funcs.decode = &print_fixed64;
testmessage.fixed64value.arg = "fixed64value: %lld\n";
testmessage.repeatedstring.funcs.decode = &print_string;
testmessage.repeatedstring.arg = "repeatedstring: \"%s\"\n";
if (!pb_decode(&stream, TestMessage_fields, &testmessage))
return 1;
......
......@@ -41,6 +41,22 @@ bool encode_fixed64(pb_ostream_t *stream, const pb_field_t *field, void * const
return pb_encode_fixed64(stream, &value);
}
bool encode_repeatedstring(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
{
char *str[4] = {"Hello world!", "", "Test", "Test2"};
int i;
for (i = 0; i < 4; i++)
{
if (!pb_encode_tag_for_field(stream, field))
return false;
if (!pb_encode_string(stream, (uint8_t*)str[i], strlen(str[i])))
return false;
}
return true;
}
int main()
{
uint8_t buffer[1024];
......@@ -57,6 +73,8 @@ int main()
testmessage.submsg.int32value.funcs.encode = &encode_int32;
testmessage.submsg.fixed32value.funcs.encode = &encode_fixed32;
testmessage.submsg.fixed64value.funcs.encode = &encode_fixed64;
testmessage.repeatedstring.funcs.encode = &encode_repeatedstring;
if (!pb_encode(&stream, TestMessage_fields, &testmessage))
return 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment