diff --git a/cfg/std.cfg b/cfg/std.cfg index e3bb60e2a..cb7485050 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -18,12 +18,17 @@ false false - false - false - false - false - false - false + false 0-255 + false 0-255 + false 0-255 + false 0-255 + false 0-255 + false 0-255 + false 0-255 + false 0-255 + false 0-255 + false 0-255 + false 0-255 false 0- false 0- diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 99fff7e31..47de1bf49 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2413,24 +2413,6 @@ void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numP } else reportError(tok, Severity::error, "wrongmathcall", "Passing value '#' to #() leads to undefined result."); } - -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- -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% ,|)") && - MathLib::isNegative(tok->strAt(2))) { - cctypefunctionCallError(tok, tok->str(), tok->strAt(2)); - } - } -} -void CheckOther::cctypefunctionCallError(const Token *tok, const std::string &functionName, const std::string &value) -{ - reportError(tok, Severity::error, "wrongcctypecall", "Passing value " + value + " to " + functionName + "() causes undefined behavior which may lead to a crash."); -} - //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void CheckOther::checkMisusedScopedObject() diff --git a/lib/checkother.h b/lib/checkother.h index a8a95b945..056c3a66f 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -92,7 +92,6 @@ public: checkOther.checkZeroDivision(); checkOther.checkZeroDivisionOrUselessCondition(); checkOther.checkMathFunctions(); - checkOther.checkCCTypeFunctions(); checkOther.redundantGetAndSetUserId(); checkOther.checkIncorrectLogicOperator(); @@ -174,9 +173,6 @@ public: /** @brief %Check for parameters given to math function that do not make sense*/ void checkMathFunctions(); - /** @brief %Check for parameters given to cctype function that do make error*/ - void checkCCTypeFunctions(); - /** @brief % Check for seteuid(geteuid()) or setuid(getuid())*/ void redundantGetAndSetUserId(); @@ -295,7 +291,6 @@ private: void zerodivcondError(const Token *tokcond, const Token *tokdiv); void nanInArithmeticExpressionError(const Token *tok); void mathfunctionCallError(const Token *tok, const unsigned int numParam = 1); - void cctypefunctionCallError(const Token *tok, const std::string &functionName, const std::string &value); void redundantAssignmentError(const Token *tok1, const Token* tok2, const std::string& var, bool inconclusive); void redundantAssignmentInSwitchError(const Token *tok1, const Token *tok2, const std::string &var); void redundantCopyError(const Token *tok1, const Token* tok2, const std::string& var); @@ -392,7 +387,6 @@ private: c.pointerLessThanZeroError(0, false); c.pointerPositiveError(0, false); c.SuspiciousSemicolonError(0); - c.cctypefunctionCallError(0, "funname", "value"); c.moduloAlwaysTrueFalseError(0, "1"); c.incompleteArrayFillError(0, "buffer", "memset", false); c.varFuncNullUBError(0); @@ -458,7 +452,6 @@ private: "* testing if unsigned variable is negative\n" "* testing is unsigned variable is positive\n" "* Suspicious use of ; at the end of 'if/for/while' statement.\n" - "* incorrect usage of functions from ctype library.\n" "* Comparisons of modulo results that are always true/false.\n" "* Array filled incompletely using memset/memcpy/memmove.\n" "* redundant get and set function of user id (--std=posix).\n" diff --git a/test/testother.cpp b/test/testother.cpp index b9efd260e..01b09e184 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -93,7 +93,6 @@ private: TEST_CASE(mathfunctionCall_asin); TEST_CASE(mathfunctionCall_pow); TEST_CASE(mathfunctionCall_atan2); - TEST_CASE(cctypefunctionCall); TEST_CASE(switchRedundantAssignmentTest); TEST_CASE(switchRedundantOperationTest); @@ -1778,146 +1777,6 @@ private: ASSERT_EQUALS("", errout.str()); } - void cctypefunctionCall() { - // isalnum - check("void foo()\n" - "{\n" - " std::cout << isalnum(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isalnum(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isalnum() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isalpha(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isalpha(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isalpha() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << iscntrl(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << iscntrl(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to iscntrl() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isdigit(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isdigit(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isdigit() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isgraph(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isgraph(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isgraph() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << islower(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << islower(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to islower() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isprint(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isprint(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isprint() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << ispunct(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << ispunct(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to ispunct() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isspace(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isspace(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isspace() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isupper(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isupper(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isupper() causes undefined behavior which may lead to a crash.\n", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isxdigit(61) << std::endl;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " std::cout << isxdigit(-61) << std::endl;\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -61 to isxdigit() causes 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() causes undefined behavior which may lead to a crash.\n", errout.str()); - } - void switchRedundantAssignmentTest() { check("void foo()\n"