Fixed #5401 (value flow: fp when there are increment/decrement)
This commit is contained in:
parent
1cac7e1686
commit
4647a9fc93
|
@ -490,7 +490,8 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " is assigned in conditional code");
|
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " is assigned in conditional code");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Token::findmatch(start, "++|--| %varid% ++|--|=", end, varid)) {
|
if (Token::findmatch(start, "++|-- %varid%", end, varid) ||
|
||||||
|
Token::findmatch(start, "%varid% ++|--|=", end, varid)) {
|
||||||
if (number_of_if == 0 &&
|
if (number_of_if == 0 &&
|
||||||
Token::simpleMatch(tok2, "if (") &&
|
Token::simpleMatch(tok2, "if (") &&
|
||||||
!(Token::simpleMatch(end, "} else {") &&
|
!(Token::simpleMatch(end, "} else {") &&
|
||||||
|
@ -517,6 +518,13 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bailout increment/decrement for now..
|
||||||
|
if (Token::Match(tok2->previous(), "++|-- %var%") || Token::Match(tok, "%var% ++|--")) {
|
||||||
|
if (settings->debugwarnings)
|
||||||
|
bailout(tokenlist, errorLogger, tok2, "increment/decrement of " + tok2->str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// skip if variable is conditionally used in ?: expression
|
// skip if variable is conditionally used in ?: expression
|
||||||
if (const Token *parent = skipValueInConditionalExpression(tok2)) {
|
if (const Token *parent = skipValueInConditionalExpression(tok2)) {
|
||||||
if (settings->debugwarnings)
|
if (settings->debugwarnings)
|
||||||
|
|
|
@ -477,6 +477,13 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 123));
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 123));
|
||||||
|
|
||||||
|
code = "void f() {\n"
|
||||||
|
" int x = 9;\n"
|
||||||
|
" --x;\n"
|
||||||
|
" return x;\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 4U, 9));
|
||||||
|
|
||||||
// function
|
// function
|
||||||
code = "void f() {\n"
|
code = "void f() {\n"
|
||||||
" char *x = 0;\n"
|
" char *x = 0;\n"
|
||||||
|
@ -508,6 +515,16 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 123));
|
ASSERT_EQUALS(false, testValueOfX(code, 4U, 123));
|
||||||
|
|
||||||
|
code = "void f(int a) {\n"
|
||||||
|
" int x = 123;\n"
|
||||||
|
" if (a > 1)\n"
|
||||||
|
" ++x;\n"
|
||||||
|
" else\n"
|
||||||
|
" ++x;\n"
|
||||||
|
" return 2 + x;\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 4U, 123));
|
||||||
|
|
||||||
code = "void f() {\n"
|
code = "void f() {\n"
|
||||||
" int x = 1;\n"
|
" int x = 1;\n"
|
||||||
" if (condition1) x = 2;\n"
|
" if (condition1) x = 2;\n"
|
||||||
|
|
Loading…
Reference in New Issue