Skip to content

Commit 44ff22f

Browse files
committed
Fixed #9276 (FP literalWithCharPtrCompare)
1 parent 120c572 commit 44ff22f

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/checkstring.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ void CheckString::checkSuspiciousStringCompare()
181181
else if (!Token::Match(litTok, "%char%|%num%|%str%"))
182182
continue;
183183

184+
if (mTokenizer->isCPP() && (!varTok->valueType() || !varTok->valueType()->isIntegral()))
185+
continue;
186+
184187
// Pointer addition?
185188
if (varTok->str() == "+" && mTokenizer->isC()) {
186189
const Token * const tokens[2] = { varTok->astOperand1(), varTok->astOperand2() };

test/teststring.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ class TestString : public TestFixture {
393393
" if (example.buffer == \"test\") ;\n"
394394
"}\n", "test.c");
395395
ASSERT_EQUALS("[test.c:6]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead?\n", errout.str());
396+
397+
// #9726
398+
check("void f(std::vector<std::string> theArgs) {\n"
399+
" std::string arg1(*theArgs.begin());\n"
400+
" if(arg1 == \"aaa\") {}\n"
401+
"}");
402+
ASSERT_EQUALS("", errout.str());
396403
}
397404

398405
void suspiciousStringCompare_char() {

0 commit comments

Comments
 (0)