CheckString: Fix FP when macros are used.
This commit is contained in:
parent
9c8ff5b89c
commit
8e2f7812fd
|
@ -85,7 +85,8 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
|
|||
if (Token::Match(tok->tokAt(2), "%str% , %str% ,|)")) {
|
||||
const std::string &str1 = tok->strAt(2);
|
||||
const std::string &str2 = tok->strAt(4);
|
||||
alwaysTrueFalseStringCompareError(tok, str1, str2);
|
||||
if (!tok->isExpandedMacro() && !tok->tokAt(2)->isExpandedMacro() && !tok->tokAt(4)->isExpandedMacro())
|
||||
alwaysTrueFalseStringCompareError(tok, str1, str2);
|
||||
tok = tok->tokAt(5);
|
||||
} else if (Token::Match(tok->tokAt(2), "%name% , %name% ,|)")) {
|
||||
const std::string &str1 = tok->strAt(2);
|
||||
|
|
|
@ -155,6 +155,16 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Unnecessary comparison of static strings.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" if (strcmp($\"00FF00\", \"00FF00\") == 0) {}"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" if ($strcmp(\"00FF00\", \"00FF00\") == 0) {}"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("int main()\n"
|
||||
"{\n"
|
||||
" if (stricmp(\"hotdog\",\"HOTdog\") == 0)"
|
||||
|
|
Loading…
Reference in New Issue