diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2014-08-10 13:01:09 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2014-08-10 13:01:09 +0300 |
commit | 7edf250a627b56c43e44de546b73bf113d9dea59 (patch) | |
tree | 79b4c0f96a62d77664f01db144b25aa25217f974 /pb_decode.c | |
parent | a641e21b34aed824b6b919f7ab9937eaadf09473 (diff) |
Switch pb_encode to use the common iterator logic in pb_common.c
Update issue 128
Status: FixedInGit
Diffstat (limited to 'pb_decode.c')
-rw-r--r-- | pb_decode.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/pb_decode.c b/pb_decode.c index 40da1aa4..3e817cc8 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -616,7 +616,7 @@ static bool checkreturn default_extension_decoder(pb_istream_t *stream, /* Fake a field iterator for the extension field. * It is not actually safe to advance this iterator, but decode_field * will not even try to. */ - pb_field_iter_begin(&iter, field, extension->dest); + (void)pb_field_iter_begin(&iter, field, extension->dest); iter.pData = extension->dest; iter.pSize = &extension->found; @@ -668,16 +668,14 @@ static bool checkreturn find_extension_field(pb_field_iter_t *iter) static void pb_message_set_to_defaults(const pb_field_t fields[], void *dest_struct) { pb_field_iter_t iter; - pb_field_iter_begin(&iter, fields, dest_struct); + + if (!pb_field_iter_begin(&iter, fields, dest_struct)) + return; /* Empty message type */ do { pb_type_t type; type = iter.pos->type; - - /* Avoid crash on empty message types (zero fields) */ - if (iter.pos->tag == 0) - continue; if (PB_ATYPE(type) == PB_ATYPE_STATIC) { @@ -738,7 +736,9 @@ bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[ uint32_t extension_range_start = 0; pb_field_iter_t iter; - pb_field_iter_begin(&iter, fields, dest_struct); + /* Return value ignored, as empty message types will be correctly handled by + * pb_field_iter_find() anyway. */ + (void)pb_field_iter_begin(&iter, fields, dest_struct); while (stream->bytes_left) { @@ -859,17 +859,15 @@ bool pb_decode_delimited(pb_istream_t *stream, const pb_field_t fields[], void * void pb_release(const pb_field_t fields[], void *dest_struct) { pb_field_iter_t iter; - pb_field_iter_begin(&iter, fields, dest_struct); + + if (!pb_field_iter_begin(&iter, fields, dest_struct)) + return; /* Empty message type */ do { pb_type_t type; type = iter.pos->type; - /* Avoid crash on empty message types (zero fields) */ - if (iter.pos->tag == 0) - continue; - if (PB_ATYPE(type) == PB_ATYPE_POINTER) { if (PB_HTYPE(type) == PB_HTYPE_REPEATED && |