Skip to content

Commit 3aa29a1

Browse files
Update testnullpointer.cpp
1 parent b3e95d3 commit 3aa29a1

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎test/testnullpointer.cpp‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class TestNullPointer : public TestFixture {
173173
TEST_CASE(nullpointerSmartPointer);
174174
TEST_CASE(nullpointerOutOfMemory);
175175
TEST_CASE(nullpointerOutOfResources);
176+
TEST_CASE(nullpointerErrorPath);
176177
TEST_CASE(functioncall);
177178
TEST_CASE(functioncalllibrary); // use Library to parse function call
178179
TEST_CASE(functioncallDefaultArguments);
@@ -2488,7 +2489,7 @@ class TestNullPointer : public TestFixture {
24882489
" *p = 0;\n"
24892490
" }\n"
24902491
"}\n");
2491-
ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference: p [nullPointer]\n", errout_str());
2492+
ASSERT_EQUALS("[test.cpp:4:10]: (warning) Null pointer dereference: p [nullPointer]\n", errout_str());
24922493
}
24932494

24942495
void nullpointer78() // #7802
@@ -4100,10 +4101,10 @@ class TestNullPointer : public TestFixture {
41004101
" foo(p == s2);\n"
41014102
" foo(p == s3);\n"
41024103
"}\n", dinit(CheckOptions, $.inconclusive = true));
4103-
ASSERT_EQUALS("[test.cpp:4:15]: (error) Null pointer dereference: p [nullPointer]\n"
4104-
"[test.cpp:5:15]: (error) Null pointer dereference: p [nullPointer]\n"
4105-
"[test.cpp:7:9]: (error) Null pointer dereference: p [nullPointer]\n"
4106-
"[test.cpp:8:9]: (error) Null pointer dereference: p [nullPointer]\n", errout_str());
4104+
ASSERT_EQUALS("[test.cpp:4:15]: (warning) Null pointer dereference: p [nullPointer]\n"
4105+
"[test.cpp:5:15]: (warning) Null pointer dereference: p [nullPointer]\n"
4106+
"[test.cpp:7:9]: (warning) Null pointer dereference: p [nullPointer]\n"
4107+
"[test.cpp:8:9]: (warning) Null pointer dereference: p [nullPointer]\n", errout_str());
41074108

41084109
check("void f(std::string s1, const std::string& s2, const std::string* s3) {\n"
41094110
" void* p = 0;\n"
@@ -4586,6 +4587,24 @@ class TestNullPointer : public TestFixture {
45864587
errout_str());
45874588
}
45884589

4590+
void nullpointerErrorPath() {
4591+
setMultiline();
4592+
Settings s = settings;
4593+
s.templateLocation = "{file}:{line}:note:{info}\n";
4594+
check("int f(bool b) {\n"
4595+
" int* p = nullptr;\n"
4596+
" if (b)\n"
4597+
" return 0;\n"
4598+
" return *p;\n"
4599+
"}\n", s);
4600+
ASSERT_EQUALS(
4601+
"[test.cpp:5:13]: warning: Null pointer dereference: p [nullPointer]\n"
4602+
"[test.cpp:2:14]: note: Assignment 'p=nullptr', assigned value is 0\n"
4603+
"[test.cpp:3:9]: note: Assuming condition is false\n"
4604+
"[test.cpp:5:13]: note: Null pointer dereference\n",
4605+
errout_str());
4606+
}
4607+
45894608
void functioncalllibrary() {
45904609
SimpleTokenizer tokenizer(settingsDefault,*this,false);
45914610
const char code[] = "void f() { int a,b,c; x(a,b,c); }\n";

0 commit comments

Comments
 (0)