Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ int multiCompareImpl(const Token *tok, const char *haystack, nonneg int varid)
const char *needle = tok->str().c_str();
const char *needlePointer = needle;
for (;;) {
if (needlePointer == needle && haystack[0] == '%' && haystack[1] != '|' && haystack[1] != '\0' && haystack[1] != ' ') {
if (needlePointer == needle && haystack[0] == '%' && haystack[1] != '|' && haystack[1] != '\0' && haystack[1] != ' ' && haystack[1] != '=') {
const int ret = multiComparePercent(tok, haystack, varid);
if (ret < 2)
return ret;
Expand Down
4 changes: 2 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,10 @@ static void valueFlowSameExpressions(TokenList& tokenlist, const Settings& setti

long long val;

if (Token::Match(tok, "==|>=|<=|/")) {
if (Token::Match(tok, "==|>=|<=|/|/=")) {
val = 1;
}
else if (Token::Match(tok, "!=|>|<|%|-")) {
else if (Token::Match(tok, "!=|>|<|%|%=|-|-=|^|^=")) {
val = 0;
}
else
Expand Down
24 changes: 24 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5805,6 +5805,30 @@ class TestValueFlow : public TestFixture {
" bool b = x;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 1));

code = "int f(int a) {\n"
" int x = a ^ a;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));

code = "int f(int a) {\n"
" int x = a /= a;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 1));

code = "int f(int a) {\n"
" int x = a -= a;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));

code = "int f(int a) {\n"
" int x = a %= a;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
}

void valueFlowUninit() {
Expand Down
Loading