#6626 crash: Token::astOperand2() const ( do while ). Fix two segmentation faults on invalid code.
This commit is contained in:
parent
7fdbb91694
commit
9876cf2312
|
@ -438,7 +438,7 @@ void CheckBool::pointerArithBool()
|
||||||
if (tok)
|
if (tok)
|
||||||
tok = tok->astOperand1();
|
tok = tok->astOperand1();
|
||||||
} else if (scope->type == Scope::eDo)
|
} else if (scope->type == Scope::eDo)
|
||||||
tok = scope->classEnd->tokAt(2)->astOperand2();
|
tok = (scope->classEnd->tokAt(2)) ? scope->classEnd->tokAt(2)->astOperand2() : nullptr;
|
||||||
|
|
||||||
pointerArithBoolCond(tok);
|
pointerArithBoolCond(tok);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1455,6 +1455,8 @@ void CheckStl::checkDereferenceInvalidIterator()
|
||||||
const Token* startOfCondition = tok->next();
|
const Token* startOfCondition = tok->next();
|
||||||
if (i->type == Scope::eDo)
|
if (i->type == Scope::eDo)
|
||||||
startOfCondition = startOfCondition->link()->tokAt(2);
|
startOfCondition = startOfCondition->link()->tokAt(2);
|
||||||
|
if (!startOfCondition) // ticket #6626 invalid code
|
||||||
|
continue;
|
||||||
const Token* endOfCondition = startOfCondition->link();
|
const Token* endOfCondition = startOfCondition->link();
|
||||||
if (!endOfCondition)
|
if (!endOfCondition)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
TEST_CASE(garbageCode31); // #6539
|
TEST_CASE(garbageCode31); // #6539
|
||||||
TEST_CASE(garbageCode32); // #6135
|
TEST_CASE(garbageCode32); // #6135
|
||||||
TEST_CASE(garbageCode33); // #6613
|
TEST_CASE(garbageCode33); // #6613
|
||||||
|
TEST_CASE(garbageCode34); // 6626
|
||||||
|
|
||||||
TEST_CASE(garbageValueFlow);
|
TEST_CASE(garbageValueFlow);
|
||||||
TEST_CASE(garbageSymbolDatabase);
|
TEST_CASE(garbageSymbolDatabase);
|
||||||
|
@ -410,6 +411,15 @@ private:
|
||||||
checkCode("\xe2u.");
|
checkCode("\xe2u.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bug #6626 crash: Token::astOperand2() const ( do while )
|
||||||
|
void garbageCode34() {
|
||||||
|
checkCode("void foo(void) {\n"
|
||||||
|
" do\n"
|
||||||
|
" while (0);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void garbageValueFlow() {
|
void garbageValueFlow() {
|
||||||
// #6089
|
// #6089
|
||||||
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
||||||
|
|
Loading…
Reference in New Issue