Skip to content

Commit

Permalink
Merge pull request #123 from chaoticgd/bitfieldfix2
Browse files Browse the repository at this point in the history
Fix infinite loop in detect_bitfields
  • Loading branch information
chaoticgd authored Oct 21, 2023
2 parents 0448cba + 9c1a754 commit 39f331f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ccc/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,7 @@ static bool detect_bitfield(const StabsField& field, const StabsToAstState& stat

// Resolve type references.
const StabsType* type = field.type.get();
while(!type->has_body
|| type->descriptor == StabsTypeDescriptor::TYPE_REFERENCE
|| type->descriptor == StabsTypeDescriptor::CONST_QUALIFIER
|| type->descriptor == StabsTypeDescriptor::VOLATILE_QUALIFIER) {
for(s32 i = 0; i < 50; i++) {
if(!type->has_body) {
if(type->anonymous) {
return false;
Expand All @@ -340,8 +337,15 @@ static bool detect_bitfield(const StabsField& field, const StabsToAstState& stat
type = type->as<StabsTypeReferenceType>().type.get();
} else if(type->descriptor == StabsTypeDescriptor::CONST_QUALIFIER) {
type = type->as<StabsConstQualifierType>().type.get();
} else {
} else if(type->descriptor == StabsTypeDescriptor::VOLATILE_QUALIFIER) {
type = type->as<StabsVolatileQualifierType>().type.get();
} else {
break;
}

// Prevent an infinite loop if there's a cycle (fatal frame).
if(i == 49) {
return false;
}
}

Expand Down

0 comments on commit 39f331f

Please sign in to comment.