summaryrefslogtreecommitdiffstats
path: root/pb_decode.c
diff options
context:
space:
mode:
Diffstat (limited to 'pb_decode.c')
-rw-r--r--pb_decode.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/pb_decode.c b/pb_decode.c
index 601dc742..2235280e 100644
--- a/pb_decode.c
+++ b/pb_decode.c
@@ -612,6 +612,7 @@ bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field
{
bool status;
pb_istream_t substream;
+ const pb_field_t* submsg_fields = (const pb_field_t*)field->ptr;
if (!pb_make_string_substream(stream, &substream))
return false;
@@ -619,7 +620,13 @@ bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field
if (field->ptr == NULL)
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);
return status;
}