ValueFlow: better handling of goto to avoid false positives
This commit is contained in:
parent
d15c9d07d7
commit
2831bbd420
|
@ -243,11 +243,11 @@ static bool isReturn(const Token *tok)
|
|||
// noreturn function
|
||||
if (Token::simpleMatch(prev->previous(), ") ;") && Token::Match(prev->linkAt(-1)->tokAt(-2), "[;{}] %var% ("))
|
||||
return true;
|
||||
// return statement
|
||||
// return/goto statement
|
||||
prev = prev->previous();
|
||||
while (prev && !Token::Match(prev,"[;{}]"))
|
||||
prev = prev->previous();
|
||||
return Token::Match(prev, "[;{}] return");
|
||||
return Token::Match(prev, "[;{}] return|goto");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -737,6 +737,14 @@ private:
|
|||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 4U, 32));
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x = 33;\n"
|
||||
" if (x==33) goto fail;\n"
|
||||
" a[x]=0;\n"
|
||||
"fail:\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 33));
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x = 32;\n"
|
||||
" if (a==1) { z=x+12; }\n"
|
||||
|
|
Loading…
Reference in New Issue