Fixed crash on garbage code in CheckOther::checkVariableScope(). The corresponding backtrace is hosted at https://github.com/orbitcowboy/cppcheck_crash_files/blob/master/crash223.cpp
This commit is contained in:
parent
2ca47601cd
commit
a7c870bdc8
|
@ -1336,7 +1336,7 @@ void CheckOther::checkVariableScope()
|
|||
}
|
||||
bool reduce = true;
|
||||
bool used = false; // Don't warn about unused variables
|
||||
for (; tok != var->scope()->classEnd; tok = tok->next()) {
|
||||
for (; tok && tok != var->scope()->classEnd; tok = tok->next()) {
|
||||
if (tok->str() == "{" && tok->scope() != tok->previous()->scope() && !tok->isExpandedMacro() && tok->scope()->type != Scope::eLambda) {
|
||||
if (used) {
|
||||
bool used2 = false;
|
||||
|
|
|
@ -51,6 +51,7 @@ private:
|
|||
TEST_CASE(garbageCode9); // #5604
|
||||
TEST_CASE(garbageCode10); // #6127
|
||||
TEST_CASE(garbageCode11);
|
||||
TEST_CASE(garbageCode12);
|
||||
|
||||
TEST_CASE(astGarbage);
|
||||
}
|
||||
|
@ -60,6 +61,12 @@ private:
|
|||
|
||||
Settings settings;
|
||||
settings.debugwarnings = true;
|
||||
settings.addEnabled("style");
|
||||
settings.addEnabled("warning");
|
||||
settings.addEnabled("portability");
|
||||
settings.addEnabled("performance");
|
||||
settings.inconclusive = true;
|
||||
settings.experimental = true;
|
||||
|
||||
// tokenize..
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
|
@ -238,6 +245,10 @@ private:
|
|||
checkCode("( ) &");
|
||||
}
|
||||
|
||||
void garbageCode12() { // do not crash
|
||||
checkCode("{ g; S (void) { struct } { } int &g; }");
|
||||
}
|
||||
|
||||
void astGarbage() {
|
||||
checkCode("--"); // don't crash
|
||||
|
||||
|
|
Loading…
Reference in New Issue