From 9ae59290dd743a0549f7434cc4cc2ac5bcf51e53 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 7 Apr 2014 12:08:34 +0200 Subject: [PATCH] #5645 False positive Null pointer derefence about first argument to fputc() --- cfg/std.cfg | 2 +- test/testnullpointer.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 5a7755499..ccf3426bc 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -42,7 +42,7 @@ false - 0- + 0- diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 3f121dafa..857250f07 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -82,6 +82,7 @@ private: TEST_CASE(crash1); TEST_CASE(functioncallDefaultArguments); TEST_CASE(nullpointer_internal_error); // #5080 + TEST_CASE(nullpointerFputc); // #5645 FP: Null pointer dereference in fputc argument // Test that std.cfg is configured correctly TEST_CASE(stdcfg); @@ -2534,6 +2535,25 @@ private: check("void f(char * p,char * q){ strtol (p,q,0);if(!p){}}"); ASSERT_EQUALS(errp,errout.str()); } + + void nullpointerFputc() { + check("int main () {\n" + "FILE *fp = fopen(\"file.txt\", \"w+\");\n" + "fputc(000, fp); \n" + "fclose(fp);\n" + "return 0 ;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("int main () {\n" + "FILE *fp = fopen(\"file.txt\", \"w+\");\n" + "char *nullstring=0;" + "fputc(*nullstring, fp); \n" + "fclose(fp);\n" + "return 0 ;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: nullstring\n", errout.str()); + } }; REGISTER_TEST(TestNullPointer)