Skip to content

Commit

Permalink
Fix stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Nov 18, 2023
1 parent c86e159 commit 08c0c32
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ bool astHasVar(const Token * tok, nonneg int varid)
return astHasVar(tok->astOperand1(), varid) || astHasVar(tok->astOperand2(), varid);
}

bool astHasExpr(const Token * tok, nonneg int exprid)
{
if (!tok)
return false;
if (tok->exprId() == exprid)
return true;
return astHasExpr(tok->astOperand1(), exprid) || astHasExpr(tok->astOperand2(), exprid);
}

static bool astIsCharWithSign(const Token *tok, ValueType::Sign sign)
{
if (!tok)
Expand Down
1 change: 1 addition & 0 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ nonneg int astCount(const Token* tok, const char* op, int depth = 100);

bool astHasToken(const Token* root, const Token * tok);

bool astHasExpr(const Token * tok, nonneg int exprid);
bool astHasVar(const Token * tok, nonneg int varid);

bool astIsPrimitive(const Token* tok);
Expand Down
2 changes: 1 addition & 1 deletion lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ namespace {
const Token* tok = p.first.tok;
const ValueFlow::Value& value = p.second;

if (tok->str() == expr->str()) {
if (tok->str() == expr->str() && !astHasExpr(tok, expr->exprId())) {
// TODO: Handle when it is greater
if (n != astCount(tok, expr->str().c_str()))
continue;
Expand Down

0 comments on commit 08c0c32

Please sign in to comment.