Fixed #9276 (FP literalWithCharPtrCompare)

This commit is contained in:
Daniel Marjamäki 2020-06-06 17:47:30 +02:00
parent 120c572252
commit 44ff22f879
2 changed files with 10 additions and 0 deletions

View File

@ -181,6 +181,9 @@ void CheckString::checkSuspiciousStringCompare()
else if (!Token::Match(litTok, "%char%|%num%|%str%"))
continue;
if (mTokenizer->isCPP() && (!varTok->valueType() || !varTok->valueType()->isIntegral()))
continue;
// Pointer addition?
if (varTok->str() == "+" && mTokenizer->isC()) {
const Token * const tokens[2] = { varTok->astOperand1(), varTok->astOperand2() };

View File

@ -393,6 +393,13 @@ private:
" if (example.buffer == \"test\") ;\n"
"}\n", "test.c");
ASSERT_EQUALS("[test.c:6]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead?\n", errout.str());
// #9726
check("void f(std::vector<std::string> theArgs) {\n"
" std::string arg1(*theArgs.begin());\n"
" if(arg1 == \"aaa\") {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void suspiciousStringCompare_char() {