CheckNullPointer: Update std.cfg and test that updates are correct

This commit is contained in:
Daniel Marjamäki 2014-01-27 17:33:16 +01:00
parent 6e6de82323
commit b8b573321e
2 changed files with 68 additions and 22 deletions

View File

@ -36,21 +36,21 @@
<function name="memmove"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/></arg> <arg nr="2"><not-null/><not-uninit/></arg> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>
<function name="memset"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/></arg> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>
<function name="strcat"> <noreturn>false</noreturn> <leak-ignore/> </function>
<function name="strchr"> <noreturn>false</noreturn> <leak-ignore/> </function>
<function name="strcpy"> <noreturn>false</noreturn> <leak-ignore/> </function>
<function name="strcmp"> <noreturn>false</noreturn> <leak-ignore/> </function>
<function name="strdup"> <noreturn>false</noreturn> <leak-ignore/> </function>
<function name="strlen"> <noreturn>false</noreturn> <leak-ignore/> </function>
<function name="strncat"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>
<function name="strncpy"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>
<function name="strncmp"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>
<function name="strstr"> <noreturn>false</noreturn> <leak-ignore/> </function>
<function name="strcat"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> </function>
<function name="strchr"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> </function>
<function name="strcpy"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/></arg> <arg nr="2"><not-null/><not-uninit/></arg> </function>
<function name="strcmp"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> </function>
<function name="strdup"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> </function>
<function name="strlen"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> </function>
<function name="strncat"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>
<function name="strncpy"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/></arg> <arg nr="2"><not-null/><not-uninit/></arg> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>
<function name="strncmp"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>
<function name="strstr"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> </function>
<function name="strtol"> <leak-ignore/> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="strtoll"> <leak-ignore/> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="strtoul"> <leak-ignore/> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="strtoull"> <leak-ignore/> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="strtol"> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="strtoll"> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="strtoul"> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="strtoull"> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="wcstol"> <leak-ignore/> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="wcstoll"> <leak-ignore/> <arg nr="3"><valid>0,2-36</valid></arg> </function>
<function name="wcstoul"> <leak-ignore/> <arg nr="3"><valid>0,2-36</valid></arg> </function>

View File

@ -77,6 +77,9 @@ private:
TEST_CASE(crash1);
TEST_CASE(functioncallDefaultArguments);
TEST_CASE(nullpointer_internal_error); // #5080
// Test that std.cfg is configured correctly
TEST_CASE(stdcfg);
}
void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp", bool verify=true) {
@ -86,14 +89,9 @@ private:
Settings settings;
settings.addEnabled("warning");
settings.inconclusive = inconclusive;
// cfg
const char cfg[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <function name=\"memcmp\"> <arg nr=\"1\"><not-null/></arg> <arg nr=\"2\"><not-null/></arg> </function>\n"
" <function name=\"strcpy\"> <arg nr=\"1\"><not-null/></arg> <arg nr=\"2\"><not-null/></arg> </function>\n"
"</def>";
settings.library.loadxmldata(cfg, sizeof(cfg));
_lib = Library();
LOAD_LIB("std.cfg");
settings.library = _lib;
// Tokenize..
Tokenizer tokenizer(&settings, this);
@ -2391,6 +2389,54 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
// Test that std.cfg is configured correctly
void stdcfg() {
const char errp[] = "[test.cpp:1] -> [test.cpp:1]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n";
const char errpq[] = "[test.cpp:1] -> [test.cpp:1]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n"
"[test.cpp:1] -> [test.cpp:1]: (warning) Possible null pointer dereference: q - otherwise it is redundant to check it against null.\n";
// str..
check("void f(char*p){ strchr (p,c);if(!p){}}");
ASSERT_EQUALS(errp,errout.str());
check("void f(char*p){ strdup (p);if(!p){}}");
ASSERT_EQUALS(errp,errout.str());
check("void f(char*p){ strlen (p);if(!p){}}");
ASSERT_EQUALS(errp,errout.str());
check("void f(char*p,char*q){ strcpy (p,q);if(!p||!q){}}");
ASSERT_EQUALS(errpq,errout.str());
check("void f(char*p,char*q){ strcat (p,q);if(!p||!q){}}");
ASSERT_EQUALS(errpq,errout.str());
check("void f(char*p,char*q){ strcmp (p,q);if(!p||!q){}}");
ASSERT_EQUALS(errpq,errout.str());
check("void f(char*p,char*q){ strncpy (p,q,1);if(!p||!q){}}");
ASSERT_EQUALS(errpq,errout.str());
check("void f(char*p,char*q){ strncat (p,q,1);if(!p||!q){}}");
ASSERT_EQUALS(errpq,errout.str());
check("void f(char*p,char*q){ strncmp (p,q,1);if(!p||!q){}}");
ASSERT_EQUALS(errpq,errout.str());
check("void f(char*p,char*q){ strstr (p,q);if(!p||!q){}}");
ASSERT_EQUALS(errpq,errout.str());
// strtol etc
check("void f(char*p,char*q){ strtoul (p,q,0);if(!p){}}");
ASSERT_EQUALS(errp,errout.str());
check("void f(char*p,char*q){ strtoull (p,q,0);if(!p){}}");
ASSERT_EQUALS(errp,errout.str());
check("void f(char*p,char*q){ strtol (p,q,0);if(!p){}}");
ASSERT_EQUALS(errp,errout.str());
}
};
REGISTER_TEST(TestNullPointer)