Fix #6720 and #6721 (Crashes on garbage code)

Local fixes to avoid access to NULL-token
This commit is contained in:
amai2012 2015-05-29 19:30:55 +02:00
parent 9236ea4a20
commit 5b347c537b
3 changed files with 14 additions and 0 deletions

View File

@ -1721,6 +1721,8 @@ void CheckBufferOverrun::arrayIndexThenCheck()
if (tok->type() == Token::eComparisonOp)
tok = tok->tokAt(2);
if (!tok)
break;
// skip close parentheses
if (tok->str() == ")")
tok = tok->next();

View File

@ -98,6 +98,8 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
alwaysTrueFalseStringCompareError(tok, str1, str2);
tok = tok->tokAt(5);
}
if (!tok)
break;
}
}

View File

@ -90,6 +90,8 @@ private:
TEST_CASE(garbageCode49); // #6715
TEST_CASE(garbageCode50); // #6718
TEST_CASE(garbageCode51); // #6719
TEST_CASE(garbageCode52); // #6720
TEST_CASE(garbageCode53); // #6721
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -515,6 +517,14 @@ private:
checkCode(" (const \"C\" ...); struct base { int f2; base (int arg1, int arg2); }; global_base(0x55, 0xff); { ((global_base.f1 0x55) (global_base.f2 0xff)) { } } base::base(int arg1, int arg2) { f2 = }");
}
void garbageCode52() { // #6720
checkCode("a \"b\" not_eq \"c\"");
}
void garbageCode53() { // #6721
checkCode("{ { } }; void foo (struct int i) { x->b[i] = = }");
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"