#6838 cppcheck hangs on some strange input code. Token::astOperand1/2 throw internal error on garbage code instead of creating endless recursion in AST
This commit is contained in:
parent
177fd9c79d
commit
b30d9ffe98
|
@ -1103,8 +1103,11 @@ void Token::astOperand1(Token *tok)
|
|||
_astOperand1->_astParent = nullptr;
|
||||
// goto parent operator
|
||||
if (tok) {
|
||||
while (tok->_astParent)
|
||||
while (tok->_astParent) {
|
||||
if (tok->_astParent == this) // #6838 avoid hang on garbage code
|
||||
throw InternalError(this, "Internal error. oken::astOperand1() recursive dependency.");
|
||||
tok = tok->_astParent;
|
||||
}
|
||||
tok->_astParent = this;
|
||||
}
|
||||
_astOperand1 = tok;
|
||||
|
@ -1116,8 +1119,11 @@ void Token::astOperand2(Token *tok)
|
|||
_astOperand2->_astParent = nullptr;
|
||||
// goto parent operator
|
||||
if (tok) {
|
||||
while (tok->_astParent)
|
||||
while (tok->_astParent) {
|
||||
if (tok->_astParent == this) // #6838 avoid hang on garbage code
|
||||
throw InternalError(this, "Internal error. oken::astOperand1() recursive dependency.");
|
||||
tok = tok->_astParent;
|
||||
}
|
||||
tok->_astParent = this;
|
||||
}
|
||||
_astOperand2 = tok;
|
||||
|
|
|
@ -137,6 +137,7 @@ private:
|
|||
TEST_CASE(garbageCode95);
|
||||
TEST_CASE(garbageCode96);
|
||||
TEST_CASE(garbageCode97);
|
||||
TEST_CASE(garbageCode98);
|
||||
|
||||
TEST_CASE(garbageValueFlow);
|
||||
TEST_CASE(garbageSymbolDatabase);
|
||||
|
@ -761,6 +762,12 @@ private:
|
|||
ASSERT_THROW(checkCode("namespace A {> } class A{ { }} class A : T< ;"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode98() { // #6838
|
||||
ASSERT_THROW(checkCode("for (cocon To::ta@Taaaaaforconst oken aaaaaaaaaaaa5Dl()\n"
|
||||
"const unsiged in;\n"
|
||||
"fon *tok = f);.s(Token i = d-)L;"), InternalError);
|
||||
}
|
||||
|
||||
void garbageValueFlow() {
|
||||
// #6089
|
||||
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
||||
|
|
Loading…
Reference in New Issue