diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 1f9171a7ebb..7ef6b03d4ea 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -546,11 +546,11 @@ void CheckNullPointer::pointerArithmeticError(const Token* tok, const ValueFlow: std::string id = "nullPointerArithmetic"; if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) { - errmsg = "If memory allocation fail: " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1)); + errmsg = "If memory allocation fails: " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1)); id += "OutOfMemory"; } else if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) { - errmsg = "If resource allocation fail: " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1)); + errmsg = "If resource allocation fails: " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1)); id += "OutOfResources"; } diff --git a/lib/library.cpp b/lib/library.cpp index 9b6c46f4410..b6f801589d3 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1597,6 +1597,10 @@ const std::string& Library::returnValue(const Token *ftok) const const std::string& Library::returnValueType(const Token *ftok) const { + while (Token::simpleMatch(ftok, "::")) + ftok = ftok->astOperand2() ? ftok->astOperand2() : ftok->astOperand1(); + if (!ftok) + return mEmptyString; if (isNotLibraryFunction(ftok)) { if (Token::simpleMatch(ftok->astParent(), ".") && ftok->astParent()->astOperand1()) { const Token* contTok = ftok->astParent()->astOperand1(); diff --git a/test/cfg/opencv2.cpp b/test/cfg/opencv2.cpp index 56eacfd5210..6e79caab8d0 100644 --- a/test/cfg/opencv2.cpp +++ b/test/cfg/opencv2.cpp @@ -45,7 +45,7 @@ void memleak() { // cppcheck-suppress cstyleCast const char * pBuf = (char *)cv::fastMalloc(1000); - // cppcheck-suppress [uninitdata, valueFlowBailoutIncompleteVar] + // cppcheck-suppress [uninitdata, valueFlowBailoutIncompleteVar, nullPointerOutOfMemory] std::cout << pBuf; // cppcheck-suppress memleak } diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 48c4efc4418..a3345425d41 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -1854,6 +1854,7 @@ void uninitar_fopen(void) const char *mode; // cppcheck-suppress uninitvar FILE * fp = std::fopen(filename, mode); + // cppcheck-suppress nullPointerOutOfResources fclose(fp); } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 33352085208..31ac0abc492 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4101,7 +4101,14 @@ class TestNullPointer : public TestFixture { " *(p+2) = 0;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) If memory allocation fail: pointer addition with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3]: (error) If memory allocation fails: pointer addition with NULL pointer.\n", errout_str()); + + check("void f() {\n" // #13676 + " int* q = static_cast(std::malloc(4));\n" + " *q = 0;\n" + " std::free(q);\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (warning) If memory allocation fails, then there is a possible null pointer dereference: q\n", errout_str()); } void functioncall() { // #3443 - function calls