Refactor isVLAIndex
This commit is contained in:
parent
8f164d9602
commit
2214ef5359
|
@ -1081,30 +1081,22 @@ void CheckBufferOverrun::checkScope_inner(const Token *tok, const ArrayInfo &arr
|
||||||
// Negative size in array declarations
|
// Negative size in array declarations
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
static bool isVLAIndex(const Token *index)
|
static bool isVLAIndex(const Token *tok)
|
||||||
{
|
{
|
||||||
std::stack<const Token *> tokens;
|
if (!tok)
|
||||||
tokens.push(index);
|
return false;
|
||||||
while (!tokens.empty()) {
|
if (tok->varId() != 0U)
|
||||||
const Token *tok = tokens.top();
|
return true;
|
||||||
tokens.pop();
|
if (tok->str() == "?") {
|
||||||
if (!tok)
|
// this is a VLA index if both expressions around the ":" is VLA index
|
||||||
continue;
|
if (tok->astOperand2() &&
|
||||||
if (tok->varId() != 0U)
|
tok->astOperand2()->str() == ":" &&
|
||||||
|
isVLAIndex(tok->astOperand2()->astOperand1()) &&
|
||||||
|
isVLAIndex(tok->astOperand2()->astOperand2()))
|
||||||
return true;
|
return true;
|
||||||
if (tok->str() == "?") {
|
return false;
|
||||||
// this is a VLA index if both expressions around the ":" is VLA index
|
|
||||||
if (tok->astOperand2() &&
|
|
||||||
tok->astOperand2()->str() == ":" &&
|
|
||||||
isVLAIndex(tok->astOperand2()->astOperand1()) &&
|
|
||||||
isVLAIndex(tok->astOperand2()->astOperand2()))
|
|
||||||
return true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
tokens.push(tok->astOperand1());
|
|
||||||
tokens.push(tok->astOperand2());
|
|
||||||
}
|
}
|
||||||
return false;
|
return isVLAIndex(tok->astOperand1()) || isVLAIndex(tok->astOperand2());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBufferOverrun::negativeArraySize()
|
void CheckBufferOverrun::negativeArraySize()
|
||||||
|
|
Loading…
Reference in New Issue