summaryrefslogtreecommitdiffstats
path: root/pb_decode.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-08-26 09:56:11 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-08-26 11:04:55 +0300
commit160f02e4d0f8f404492ffd4d7611ba4478190da2 (patch)
treedc0548d7d3ca57af153627579164694deded3d26 /pb_decode.c
parenta7a6cdad8885b48a648ad69c9c0a3f01e0707934 (diff)
Add pb_decode_noinit and use it from pb_dec_submessage.
This avoids double initialization when decoding nested submessages. Fixes an issue with submessage arrays that was present in previous version of this patch. Update issue 28 Status: FixedInGit
Diffstat (limited to 'pb_decode.c')
-rw-r--r--pb_decode.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/pb_decode.c b/pb_decode.c
index 9d65504c..601dc742 100644
--- a/pb_decode.c
+++ b/pb_decode.c
@@ -415,13 +415,11 @@ static void pb_message_set_to_defaults(const pb_field_t fields[], void *dest_str
* Decode all fields *
*********************/
-bool checkreturn pb_decode(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
+bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
{
uint8_t fields_seen[(PB_MAX_REQUIRED_FIELDS + 7) / 8] = {0}; /* Used to check for required fields */
pb_field_iterator_t iter;
- pb_message_set_to_defaults(fields, dest_struct);
-
pb_field_init(&iter, fields, dest_struct);
while (stream->bytes_left)
@@ -470,6 +468,12 @@ bool checkreturn pb_decode(pb_istream_t *stream, const pb_field_t fields[], void
return true;
}
+bool checkreturn pb_decode(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
+{
+ pb_message_set_to_defaults(fields, dest_struct);
+ return pb_decode_noinit(stream, fields, dest_struct);
+}
+
/* Field decoders */
bool pb_decode_svarint(pb_istream_t *stream, int64_t *dest)
@@ -615,7 +619,7 @@ 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(&substream, (pb_field_t*)field->ptr, dest);
+ status = pb_decode_noinit(&substream, (pb_field_t*)field->ptr, dest);
pb_close_string_substream(stream, &substream);
return status;
}