Add asserts for unlinked mini tables.

In particular upb doesn't handle unlinked groups yet which requires checks to make sure callers did link group subs.

PiperOrigin-RevId: 479702475
pull/13171/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 85f7d2d065
commit 50d36a62b0
  1. 3
      upb/decode.c

@ -207,6 +207,7 @@ static upb_Message* _upb_Decoder_NewSubMessage(
upb_Decoder* d, const upb_MiniTable_Sub* subs, upb_Decoder* d, const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* field) { const upb_MiniTable_Field* field) {
const upb_MiniTable* subl = subs[field->submsg_index].submsg; const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
upb_Message* msg = _upb_Message_New_inl(subl, &d->arena); upb_Message* msg = _upb_Message_New_inl(subl, &d->arena);
if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
return msg; return msg;
@ -258,6 +259,7 @@ static const char* _upb_Decoder_DecodeSubMessage(
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, int size) { const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, int size) {
int saved_delta = _upb_Decoder_PushLimit(d, ptr, size); int saved_delta = _upb_Decoder_PushLimit(d, ptr, size);
const upb_MiniTable* subl = subs[field->submsg_index].submsg; const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP);
_upb_Decoder_PopLimit(d, ptr, saved_delta); _upb_Decoder_PopLimit(d, ptr, saved_delta);
return ptr; return ptr;
@ -288,6 +290,7 @@ static const char* _upb_Decoder_DecodeKnownGroup(
upb_Decoder* d, const char* ptr, upb_Message* submsg, upb_Decoder* d, const char* ptr, upb_Message* submsg,
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) { const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) {
const upb_MiniTable* subl = subs[field->submsg_index].submsg; const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number); return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number);
} }

Loading…
Cancel
Save