@@ -132,7 +132,7 @@ parser_error_t parseTypeRef(parser_context_t *blob,
132132 }
133133
134134 if (type -> index != Void && type -> index != ById ) {
135- printItem -> itemCount ++ ;
135+ CHECK_ERROR ( addItemCount ( printItem , 1 )) ;
136136 }
137137
138138 if (printItem -> printing && printItem -> target == printItem -> itemCount ) {
@@ -336,7 +336,7 @@ static parser_error_t parseEnumerationVariantType(parser_context_t *blob,
336336 }
337337 } else {
338338 if (!isOption && !isSome ) {
339- printItem -> itemCount ++ ;
339+ CHECK_ERROR ( addItemCount ( printItem , 1 )) ;
340340 if (printItem -> printing && printItem -> target == printItem -> itemCount ) {
341341 printItem -> item .val = tmpEntry -> enumeration .name ;
342342 printItem -> item .valEnc = EncString ;
@@ -398,15 +398,15 @@ static parser_error_t parseSequenceType(parser_context_t *blob,
398398 CHECK_ERROR (readCompactU32 (blob , & sequenceLen ));
399399 TypeRef_t sequenceType = tmpEntry -> sequence ;
400400 if (sequenceLen == 0 ) {
401- printItem -> itemCount ++ ;
401+ CHECK_ERROR ( addItemCount ( printItem , 1 )) ;
402402 if (printItem -> printing && printItem -> target == printItem -> itemCount ) {
403403 printItem -> item .valEnc = EncEmptyVec ;
404404 }
405405 return parser_ok ;
406406 }
407407
408408 if (sequenceType .index == U8 ) {
409- printItem -> itemCount ++ ;
409+ CHECK_ERROR ( addItemCount ( printItem , 1 )) ;
410410 if (printItem -> printing && printItem -> target == printItem -> itemCount ) {
411411 printItem -> item .valEnc = EncHexString ;
412412 printItem -> item .val .ptr = blob -> buffer + blob -> offset ;
@@ -454,7 +454,7 @@ static parser_error_t parseArrayType(parser_context_t *blob,
454454 const uint32_t arrLen = tmpEntry -> array .len ;
455455 const TypeRef_t arrType = tmpEntry -> array .typeParam ;
456456 if (arrType .index == U8 ) {
457- printItem -> itemCount ++ ;
457+ CHECK_ERROR ( addItemCount ( printItem , 1 )) ;
458458 if (printItem -> printing && printItem -> target == printItem -> itemCount ) {
459459 printItem -> item .valEnc = EncHexString ;
460460 printItem -> item .val .ptr = blob -> buffer + blob -> offset ;
@@ -523,13 +523,8 @@ static parser_error_t parseTupleType(parser_context_t *blob,
523523 * @param printItem Pointer to the print item to update.
524524 * @return parser_error_t Error code indicating the result of the operation.
525525 */
526- parser_error_t parseMetadataEntry (
526+ static parser_error_t parseMetadataEntryInner (
527527 parser_context_t * blob , parser_context_t * metadata , uint32_t typeId , RegistryEntry_t * tmpEntry , PrintItem_t * printItem ) {
528- if (metadata == NULL || blob == NULL || tmpEntry == NULL || printItem == NULL ) {
529- return parser_no_data ;
530- }
531-
532- CHECK_ERROR (checkStack ());
533528 MEMZERO (tmpEntry , sizeof (* tmpEntry ));
534529
535530 // Get the requested entry corresponding to typeId
@@ -553,11 +548,23 @@ parser_error_t parseMetadataEntry(
553548 break ;
554549 case BitSequenceType :
555550 // TODO: implement BitSequence
556- return parser_value_out_of_range ;
557-
558551 default :
559552 return parser_value_out_of_range ;
560553 }
561554
562- return freeStack ();
555+ return parser_ok ;
556+ }
557+
558+ parser_error_t parseMetadataEntry (
559+ parser_context_t * blob , parser_context_t * metadata , uint32_t typeId , RegistryEntry_t * tmpEntry , PrintItem_t * printItem ) {
560+ if (metadata == NULL || blob == NULL || tmpEntry == NULL || printItem == NULL ) {
561+ return parser_no_data ;
562+ }
563+
564+ // Acquire a recursion slot. On failure no slot was taken, so don't free.
565+ CHECK_ERROR (checkStack ());
566+
567+ const parser_error_t err = parseMetadataEntryInner (blob , metadata , typeId , tmpEntry , printItem );
568+ (void )freeStack ();
569+ return err ;
563570}
0 commit comments