Fix oneof submessage initialization bug.

Update issue 149
Status: FixedInGit
This commit is contained in:
Petteri Aimonen
2015-03-07 10:25:09 +02:00
parent 5c16a116ec
commit ef422656a5
2 changed files with 10 additions and 2 deletions

View File

@@ -396,6 +396,10 @@ static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t
case PB_HTYPE_ONEOF: case PB_HTYPE_ONEOF:
*(pb_size_t*)iter->pSize = iter->pos->tag; *(pb_size_t*)iter->pSize = iter->pos->tag;
if (PB_LTYPE(type) == PB_LTYPE_SUBMESSAGE)
{
pb_message_set_to_defaults((const pb_field_t*)iter->pos->ptr, iter->pData);
}
return func(stream, iter->pos, iter->pData); return func(stream, iter->pos, iter->pData);
default: default:

View File

@@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <pb_decode.h> #include <pb_decode.h>
#include "oneof.pb.h" #include "oneof.pb.h"
#include "test_helpers.h" #include "test_helpers.h"
@@ -10,9 +11,12 @@
/* Test the 'OneOfMessage' */ /* Test the 'OneOfMessage' */
int test_oneof_1(pb_istream_t *stream, int option) int test_oneof_1(pb_istream_t *stream, int option)
{ {
OneOfMessage msg = OneOfMessage_init_zero; OneOfMessage msg;
int status = 0; int status = 0;
/* To better catch initialization errors */
memset(&msg, 0xAA, sizeof(msg));
if (!pb_decode(stream, OneOfMessage_fields, &msg)) if (!pb_decode(stream, OneOfMessage_fields, &msg))
{ {
printf("Decoding failed: %s\n", PB_GET_ERROR(stream)); printf("Decoding failed: %s\n", PB_GET_ERROR(stream));
@@ -124,4 +128,4 @@ int main(int argc, char **argv)
} }
return 0; return 0;
} }