Fixed #3335 (new check: warn about potential missuse of isgraph-like functions)

This commit is contained in:
Marek Zmysłowski 2011-12-29 08:08:37 +01:00 committed by Daniel Marjamäki
parent 6d98406d71
commit dd8316474a
2 changed files with 5 additions and 1 deletions

View File

@ -2209,7 +2209,7 @@ void CheckOther::checkCCTypeFunctions()
{
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (tok->varId() == 0 &&
Token::Match(tok, "isalnum|isalpha|iscntrl|isdigit|isgraph|islower|isprint|ispunct|isspace|isupper|isxdigit ( %num% )") &&
Token::Match(tok, "isalnum|isalpha|iscntrl|isdigit|isgraph|islower|isprint|ispunct|isspace|isupper|isxdigit ( %num% ,|)") &&
MathLib::isNegative(tok->strAt(2))) {
cctypefunctionCallError(tok, tok->str(), tok->tokAt(2)->str());
}

View File

@ -1166,6 +1166,10 @@ private:
" std::cout << isxdigit(-61) << std::endl;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isxdigit() cause undefined behavior, which may lead to a crash\n", errout.str());
check("void f() {\n"
"std::isgraph(-10000, loc);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Passing value -10000 to isgraph() cause undefined behavior, which may lead to a crash\n", errout.str());
}
void fflushOnInputStreamTest() {