ValueFlow: Fix FP in switch

This commit is contained in:
Daniel Marjamäki 2018-09-04 20:28:48 +02:00
parent 3a8bdad20a
commit c6d43506b6
2 changed files with 15 additions and 0 deletions

View File

@ -3478,6 +3478,8 @@ static void valueFlowContainerReverse(const Token *tok, unsigned int containerId
while (nullptr != (tok = tok->previous())) {
if (Token::Match(tok, "[{}]"))
break;
if (Token::Match(tok, "return|break|continue"))
break;
if (tok->varId() != containerId)
continue;
if (Token::Match(tok, "%name% ="))

View File

@ -3307,6 +3307,19 @@ private:
"}";
ASSERT_EQUALS("", isPossibleContainerSizeValue(tokenValues(code, "v ["), 10));
code = "void f(std::vector<std::string> params) {\n"
" switch(x) {\n"
" case CMD_RESPONSE:\n"
" if(y) { break; }\n"
" params[2];\n" // <- container use
" break;\n"
" case CMD_DELETE:\n"
" if (params.size() < 2) { }\n" // <- condition
" break;\n"
" }\n"
"}";
ASSERT(tokenValues(code, "params [ 2 ]").empty());
// valueFlowContainerForward
code = "void f(const std::list<int> &ints) {\n"
" if (ints.empty()) {}\n"