diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 4f44e71cafe..331133d43bf 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -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"; } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 455b65379bd..a9e19991242 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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 @@ -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"