From dd8316474ae7616144232b72df2c0666f2858b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Zmys=C5=82owski?= Date: Thu, 29 Dec 2011 08:08:37 +0100 Subject: [PATCH] Fixed #3335 (new check: warn about potential missuse of isgraph-like functions) --- lib/checkother.cpp | 2 +- test/testother.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index da2b94b10..94713a0f6 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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()); } diff --git a/test/testother.cpp b/test/testother.cpp index 45458c703..a47d3f6c0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {