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 reduce = true;
|
||||||
bool used = false; // Don't warn about unused variables
|
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 (tok->str() == "{" && tok->scope() != tok->previous()->scope() && !tok->isExpandedMacro() && tok->scope()->type != Scope::eLambda) {
|
||||||
if (used) {
|
if (used) {
|
||||||
bool used2 = false;
|
bool used2 = false;
|
||||||
|
|
|
@ -51,6 +51,7 @@ private:
|
||||||
TEST_CASE(garbageCode9); // #5604
|
TEST_CASE(garbageCode9); // #5604
|
||||||
TEST_CASE(garbageCode10); // #6127
|
TEST_CASE(garbageCode10); // #6127
|
||||||
TEST_CASE(garbageCode11);
|
TEST_CASE(garbageCode11);
|
||||||
|
TEST_CASE(garbageCode12);
|
||||||
|
|
||||||
TEST_CASE(astGarbage);
|
TEST_CASE(astGarbage);
|
||||||
}
|
}
|
||||||
|
@ -60,6 +61,12 @@ private:
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.debugwarnings = true;
|
settings.debugwarnings = true;
|
||||||
|
settings.addEnabled("style");
|
||||||
|
settings.addEnabled("warning");
|
||||||
|
settings.addEnabled("portability");
|
||||||
|
settings.addEnabled("performance");
|
||||||
|
settings.inconclusive = true;
|
||||||
|
settings.experimental = true;
|
||||||
|
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
@ -238,6 +245,10 @@ private:
|
||||||
checkCode("( ) &");
|
checkCode("( ) &");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void garbageCode12() { // do not crash
|
||||||
|
checkCode("{ g; S (void) { struct } { } int &g; }");
|
||||||
|
}
|
||||||
|
|
||||||
void astGarbage() {
|
void astGarbage() {
|
||||||
checkCode("--"); // don't crash
|
checkCode("--"); // don't crash
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue