Skip to content

Commit

Permalink
Add asserts for unlinked mini tables.
Browse files Browse the repository at this point in the history
In particular upb doesn't handle unlinked groups yet which requires checks to make sure callers did link group subs.

PiperOrigin-RevId: 479702475
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Oct 8, 2022
1 parent 85f7d2d commit 50d36a6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions upb/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ static upb_Message* _upb_Decoder_NewSubMessage(
upb_Decoder* d, const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* field) {
const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
upb_Message* msg = _upb_Message_New_inl(subl, &d->arena);
if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
return msg;
Expand Down Expand Up @@ -258,6 +259,7 @@ static const char* _upb_Decoder_DecodeSubMessage(
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, int size) {
int saved_delta = _upb_Decoder_PushLimit(d, ptr, size);
const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP);
_upb_Decoder_PopLimit(d, ptr, saved_delta);
return ptr;
Expand Down Expand Up @@ -288,6 +290,7 @@ static const char* _upb_Decoder_DecodeKnownGroup(
upb_Decoder* d, const char* ptr, upb_Message* submsg,
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) {
const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number);
}

Expand Down

0 comments on commit 50d36a6

Please sign in to comment.