Incorrect string compare: reduce noise when using strncmp on string literal
This commit is contained in:
parent
7496cd412c
commit
06abaf95a5
|
@ -2982,15 +2982,6 @@ void CheckOther::checkIncorrectStringCompare()
|
|||
incorrectStringCompareError(tok->next(), "substr", tok->str(), tok->tokAt(8)->str());
|
||||
}
|
||||
}
|
||||
if (Token::Match(tok, "strncmp ( %any% , %str% , %num% )"))
|
||||
{
|
||||
size_t clen = MathLib::toLongNumber(tok->tokAt(6)->str());
|
||||
size_t slen = Token::getStrLength(tok->tokAt(4));
|
||||
if (clen != slen)
|
||||
{
|
||||
incorrectStringCompareError(tok, "strncmp", tok->tokAt(4)->str(), tok->tokAt(6)->str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2241,16 +2241,6 @@ private:
|
|||
" return \"Hello\" == test.substr( 0 , 5 ) ? : 0 : 1 ;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" return strncmp(\"test\" , \"test\" , 2) ; \n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) String literal \"test\" doesn't match length argument for strncmp(2).\n", errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" return strncmp(\"test\" , \"test\" , 4) ; \n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue