Fixed #5981 (FP: nullPointer on repeated switch)
This commit is contained in:
parent
d41ef3a6d0
commit
5bdd197b01
|
@ -618,6 +618,9 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
if (varusage) {
|
if (varusage) {
|
||||||
varusagelevel = indentlevel;
|
varusagelevel = indentlevel;
|
||||||
|
|
||||||
|
if (indentlevel < 0 && tok2->str() == "switch")
|
||||||
|
return false;
|
||||||
|
|
||||||
// TODO: don't check noreturn scopes
|
// TODO: don't check noreturn scopes
|
||||||
if (number_of_if > 0U || Token::findmatch(tok2, "%varid%", start, varid)) {
|
if (number_of_if > 0U || Token::findmatch(tok2, "%varid%", start, varid)) {
|
||||||
if (settings->debugwarnings)
|
if (settings->debugwarnings)
|
||||||
|
@ -683,6 +686,7 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
const Scope *scope = tok2->scope();
|
const Scope *scope = tok2->scope();
|
||||||
if (scope && scope->type == Scope::eSwitch) {
|
if (scope && scope->type == Scope::eSwitch) {
|
||||||
tok2 = const_cast<Token *>(scope->classEnd);
|
tok2 = const_cast<Token *>(scope->classEnd);
|
||||||
|
--indentlevel;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -754,6 +754,18 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 7U, 12));
|
ASSERT_EQUALS(true, testValueOfX(code, 7U, 12));
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 7U, 34));
|
ASSERT_EQUALS(true, testValueOfX(code, 7U, 34));
|
||||||
|
|
||||||
|
code = "void f() {\n" // #5981
|
||||||
|
" int x;\n"
|
||||||
|
" switch (ab) {\n"
|
||||||
|
" case A: x = 12; break;\n"
|
||||||
|
" case B: x = 34; break;\n"
|
||||||
|
" }\n"
|
||||||
|
" switch (ab) {\n"
|
||||||
|
" case A: v = x; break;\n" // <- x is not 34
|
||||||
|
" }\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 8U, 34));
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowAfterCondition() {
|
void valueFlowAfterCondition() {
|
||||||
|
|
Loading…
Reference in New Issue