Skip to content

Commit

Permalink
issue #7527: Doxygen 1.8.17: regression of C macro expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Jan 25, 2020
1 parent dc67dbe commit 938b6df
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/pre.l
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,8 @@ static int getNextId(const QCString &expr,int p,int *l)
return -1;
}

#define MAX_EXPANSION_DEPTH 50

/*! performs recursive macro expansion on the string \a expr
* starting at position \a pos.
* May read additional characters from the input while re-scanning!
Expand All @@ -2392,7 +2394,7 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
//printf("<expandExpression: empty\n");
return TRUE;
}
if (state->expansionDict.find(expr)!=0) // check for recursive expansions
if (state->expansionDict.find(expr)!=0 && level>MAX_EXPANSION_DEPTH) // check for too deep recursive expansions
{
//printf("<expandExpression: already expanded expr='%s'\n",expr.data());
return FALSE;
Expand All @@ -2405,6 +2407,8 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
QCString expMacro;
bool definedTest=FALSE;
int i=pos,l,p,len;
int startPos = pos;
int samePosCount=0;
while ((p=getNextId(expr,i,&l))!=-1) // search for an macro name
{
bool replaced=FALSE;
Expand Down Expand Up @@ -2492,6 +2496,20 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
i=p+l+2;
//i=p+l;
}
// check for too many inplace expansions without making progress
if (i==startPos)
{
samePosCount++;
}
else
{
startPos=i;
samePosCount=0;
}
if (samePosCount>MAX_EXPANSION_DEPTH)
{
break;
}
}
else // no re-scan marker found, skip the macro name
{
Expand Down

0 comments on commit 938b6df

Please sign in to comment.