Fixed crash on garbage code (#7022)

This commit is contained in:
PKEuS 2015-10-07 13:52:06 +02:00
parent f239057e33
commit 50ed47c725
2 changed files with 7 additions and 2 deletions

View File

@ -1211,7 +1211,7 @@ std::string Token::expressionString() const
// move start to lpar in such expression: '(*it).x'
int par = 0;
for (const Token *tok = start; tok != end; tok = tok->next()) {
for (const Token *tok = start; tok && tok != end; tok = tok->next()) {
if (tok->str() == "(")
++par;
else if (tok->str() == ")") {
@ -1224,7 +1224,7 @@ std::string Token::expressionString() const
// move end to rpar in such expression: '2>(x+1)'
par = 0;
for (const Token *tok = end; tok != start; tok = tok->previous()) {
for (const Token *tok = end; tok && tok != start; tok = tok->previous()) {
if (tok->str() == ")")
++par;
else if (tok->str() == "(") {

View File

@ -171,6 +171,7 @@ private:
TEST_CASE(garbageCode129); // #7020
TEST_CASE(garbageCode130); // #7021
TEST_CASE(garbageCode131); // #7023
TEST_CASE(garbageCode132); // #7022
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -989,6 +990,10 @@ private:
// actually the invalid code should trigger an syntax error...
}
void garbageCode132() { // #7022
checkCode("() () { } { () () ({}) i() } void i(void(*ptr) ()) { ptr(!) () }");
}
void garbageValueFlow() {
// #6089