From 1fe9414757834a53eb858bb52a719c6bcd2f961a Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 31 Aug 2009 21:42:42 -0700 Subject: Change upb_msg to work with messages that have 0 fields. --- src/upb_msg.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/upb_msg.c b/src/upb_msg.c index d9a600f..9fcd22d 100644 --- a/src/upb_msg.c +++ b/src/upb_msg.c @@ -45,18 +45,16 @@ void upb_msgdef_sortfds(google_protobuf_FieldDescriptorProto **fds, size_t num) bool upb_msgdef_init(struct upb_msgdef *m, google_protobuf_DescriptorProto *d, struct upb_string fqname, bool sort, struct upb_context *c) { - /* TODO: more complete validation. */ - if(!d->set_flags.has.field) return false; - - upb_inttable_init(&m->fields_by_num, d->field->len, + int num_fields = d->set_flags.has.field ? d->field->len : 0; + upb_inttable_init(&m->fields_by_num, num_fields, sizeof(struct upb_fieldsbynum_entry)); - upb_strtable_init(&m->fields_by_name, d->field->len, + upb_strtable_init(&m->fields_by_name, num_fields, sizeof(struct upb_fieldsbyname_entry)); m->descriptor = d; m->fqname = fqname; m->context = c; - m->num_fields = d->field->len; + m->num_fields = num_fields; m->set_flags_bytes = div_round_up(m->num_fields, 8); /* These are incremented in the loop. */ m->num_required_fields = 0; @@ -97,7 +95,9 @@ bool upb_msgdef_init(struct upb_msgdef *m, google_protobuf_DescriptorProto *d, upb_strtable_insert(&m->fields_by_name, &strent.e); } - m->size = ALIGN_UP(m->size, max_align); + if(max_align > 0) + m->size = ALIGN_UP(m->size, max_align); + return true; } -- cgit v1.2.3