ValueFlow: better handling of goto to avoid false positives

This commit is contained in:
Daniel Marjamäki 2015-01-01 14:29:49 +01:00
parent d15c9d07d7
commit 2831bbd420
2 changed files with 10 additions and 2 deletions

View File

@ -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;
}

View File

@ -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"