Incorrect string compare: reduce noise when using strncmp on string literal

This commit is contained in:
Daniel Marjamäki 2011-03-07 21:37:13 +01:00
parent 7496cd412c
commit 06abaf95a5
2 changed files with 0 additions and 19 deletions

View File

@ -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());
}
}
}
}

View File

@ -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());
}