Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
4 changes: 4 additions & 0 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/opencv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 8 additions & 1 deletion test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int*>(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
Expand Down