diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-01-11 19:46:15 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-01-11 19:46:15 +0200 |
commit | d2e023e3e5ef888e176292f149d1ba93ba270c94 (patch) | |
tree | 0670534d7f96dfaa1db888af656416b0969f72fc /pb_common.c | |
parent | 8d12fecc7e4fb6899eb0d013abe0d6a5e03447ce (diff) |
Bugfixes for oneof support.
Fixes crashes / memory leaks when using pointer type fields.
Also fixes initialization of which_oneof fields.
Diffstat (limited to 'pb_common.c')
-rw-r--r-- | pb_common.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/pb_common.c b/pb_common.c index 98964850..385c0193 100644 --- a/pb_common.c +++ b/pb_common.c @@ -41,8 +41,15 @@ bool pb_field_iter_next(pb_field_iter_t *iter) /* Increment the pointers based on previous field size */ size_t prev_size = prev_field->data_size; - if (PB_ATYPE(prev_field->type) == PB_ATYPE_STATIC && - PB_HTYPE(prev_field->type) == PB_HTYPE_REPEATED) + if (PB_HTYPE(prev_field->type) == PB_HTYPE_ONEOF && + PB_HTYPE(iter->pos->type) == PB_HTYPE_ONEOF) + { + /* Don't advance pointers inside unions */ + prev_size = 0; + iter->pData = (char*)iter->pData - prev_field->data_offset; + } + else if (PB_ATYPE(prev_field->type) == PB_ATYPE_STATIC && + PB_HTYPE(prev_field->type) == PB_HTYPE_REPEATED) { /* In static arrays, the data_size tells the size of a single entry and * array_size is the number of entries */ @@ -54,14 +61,7 @@ bool pb_field_iter_next(pb_field_iter_t *iter) * The data_size only applies to the dynamically allocated area. */ prev_size = sizeof(void*); } - else if (PB_HTYPE(prev_field->type) == PB_HTYPE_ONEOF && - PB_HTYPE(iter->pos->type) == PB_HTYPE_ONEOF) - { - /* Don't advance pointers inside unions */ - prev_size = 0; - iter->pData = (char*)iter->pData - prev_field->data_offset; - } - + if (PB_HTYPE(prev_field->type) == PB_HTYPE_REQUIRED) { /* Count the required fields, in order to check their presence in the |