#5645 False positive Null pointer derefence about first argument to fputc()

This commit is contained in:
unknown 2014-04-07 12:08:34 +02:00
parent d7e2e3bd5e
commit 9ae59290dd
2 changed files with 21 additions and 1 deletions

View File

@ -42,7 +42,7 @@
<function name="fputc">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1"><not-null/><not-uninit/><not-bool/><valid>0-</valid></arg>
<arg nr="1"><not-uninit/><not-bool/><valid>0-</valid></arg>
<arg nr="2"><not-null/><not-uninit/></arg>
</function>
<function name="fputs">

View File

@ -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)