Skip to content

Commit 05f0334

Browse files
committed
Add test
1 parent 901a331 commit 05f0334

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

test/testnullpointer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class TestNullPointer : public TestFixture {
166166
TEST_CASE(nullpointerStdStream);
167167
TEST_CASE(nullpointerSmartPointer);
168168
TEST_CASE(nullpointerOutOfMemory);
169+
TEST_CASE(nullpointerOutOfResources);
169170
TEST_CASE(functioncall);
170171
TEST_CASE(functioncalllibrary); // use Library to parse function call
171172
TEST_CASE(functioncallDefaultArguments);
@@ -4234,6 +4235,18 @@ class TestNullPointer : public TestFixture {
42344235
}
42354236
}
42364237

4238+
void nullpointerOutOfResources() {
4239+
check("void f() {\n"
4240+
" FILE* fid = fopen(\"x.txt\", \"w\");\n"
4241+
" fprintf(fid, \"abcdef\");\n"
4242+
" fclose(fid);\n"
4243+
"}\n");
4244+
ASSERT_EQUALS(
4245+
"[test.cpp:3:13]: (warning) If resource allocation fails, then there is a possible null pointer dereference: fid [nullPointerOutOfResources]\n"
4246+
"[test.cpp:4:12]: (warning) If resource allocation fails, then there is a possible null pointer dereference: fid [nullPointerOutOfResources]\n",
4247+
errout_str());
4248+
}
4249+
42374250
void functioncalllibrary() {
42384251
SimpleTokenizer tokenizer(settingsDefault,*this,false);
42394252
const char code[] = "void f() { int a,b,c; x(a,b,c); }";

0 commit comments

Comments
 (0)