diff --git a/cfg/std.cfg b/cfg/std.cfg index ccf3426bc..f33ccd684 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -154,7 +154,7 @@ false - 0- + 0- 0- diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index eb9c5fdc6..2b7aa0d05 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -83,6 +83,7 @@ private: TEST_CASE(functioncallDefaultArguments); TEST_CASE(nullpointer_internal_error); // #5080 TEST_CASE(nullpointerFputc); // #5645 FP: Null pointer dereference in fputc argument + TEST_CASE(nullpointerMemchr); // Test that std.cfg is configured correctly TEST_CASE(stdcfg); @@ -2554,6 +2555,24 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: nullstring\n", errout.str()); } + + void nullpointerMemchr() { + check("void f (char *p, char *s) {\n" + " p = memchr (s, 'p', strlen(s));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f (char *p, char *s) {\n" + " p = memchr (s, 0, strlen(s));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f (char *p) {\n" + " char *s = 0;\n" + " p = memchr (s, 0, strlen(s));\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: s\n", errout.str()); + } }; REGISTER_TEST(TestNullPointer)