#5734 A FP literalWithCharPtrCompare was issued upon comparison with a char referenced within a string literal
This commit is contained in:
parent
520aaf71b8
commit
17ec0af6a7
|
@ -2914,6 +2914,9 @@ void CheckOther::checkSuspiciousStringCompare()
|
|||
|
||||
if (varTok->strAt(-1) == "+" || litTok->strAt(1) == "+")
|
||||
continue;
|
||||
// rough filter for index access (#5734). Might cause false negatives in multidimensional structures
|
||||
if (Token::simpleMatch(varTok->tokAt(1), "[") || Token::simpleMatch(litTok->tokAt(1), "["))
|
||||
continue;
|
||||
|
||||
if ((varTok->type() == Token::eString || varTok->type() == Token::eVariable) && (litTok->type() == Token::eString || litTok->type() == Token::eVariable) && litTok->type() != varTok->type()) {
|
||||
if (varTok->type() == Token::eString)
|
||||
|
|
|
@ -5107,6 +5107,20 @@ private:
|
|||
TODO_ASSERT_EQUALS("[test.cpp:2]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead?\n",
|
||||
"",
|
||||
errout.str());
|
||||
|
||||
// Ticket #5734
|
||||
check("int foo(char c) {\n"
|
||||
"return c == '42';}", "test.cpp");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("int foo(char c) {\n"
|
||||
"return c == '42';}", "test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("int foo(char c) {\n"
|
||||
"return c == \"42\"[0];}", "test.cpp", false, true, false, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("int foo(char c) {\n"
|
||||
"return c == \"42\"[0];}", "test.c", false, true, false, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void check_signOfUnsignedVariable(const char code[], bool inconclusive=false) {
|
||||
|
|
Loading…
Reference in New Issue