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
10 changes: 2 additions & 8 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,11 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var

std::string id = "nullPointer";
if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) {
if (errmsg.compare(0, 9, "Possible ") == 0)
errmsg = "If memory allocation fail: " + errmsg.substr(9);
else
errmsg = "If memory allocation fail: " + errmsg;
errmsg = "If memory allocation fails, then there is a " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1));
id += "OutOfMemory";
}
else if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) {
if (errmsg.compare(0, 9, "Possible ") == 0)
errmsg = "If resource allocation fail: " + errmsg.substr(9);
else
errmsg = "If resource allocation fail: " + errmsg;
errmsg = "If resource allocation fails, then there is a " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1));
id += "OutOfResources";
}

Expand Down
4 changes: 2 additions & 2 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2769,7 +2769,7 @@ class TestNullPointer : public TestFixture {
" (*kep)->next = 0;\n"
" (*kep)->len = slen;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (warning) If memory allocation fail: null pointer dereference: *kep\n", errout_str());
ASSERT_EQUALS("[test.cpp:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: *kep\n", errout_str());
}

void nullpointer95() // #11142
Expand Down Expand Up @@ -4087,7 +4087,7 @@ class TestNullPointer : public TestFixture {
" *p = 0;\n"
" free(p);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) If memory allocation fail: null pointer dereference: p\n", errout_str());
ASSERT_EQUALS("[test.cpp:3]: (warning) If memory allocation fails, then there is a possible null pointer dereference: p\n", errout_str());

check("void f() {\n"
" int *p = malloc(10);\n"
Expand Down
Loading