TestUninitVar: move out posix.cfg testing

This commit is contained in:
Daniel Marjamäki 2015-02-17 18:08:19 +01:00
parent e9663873e5
commit e5c098c7de
3 changed files with 12 additions and 59 deletions

View File

@ -441,6 +441,7 @@
</arg>
</function>
<function name="write">
<noreturn>false</noreturn>
<arg nr="1">
<not-uninit/>
</arg>

View File

@ -114,3 +114,14 @@ void invalidFunctionArg() {
// cppcheck-suppress invalidFunctionArg
usleep(1000000);
}
void uninitvar(int fd) {
int x;
char buf[2];
// cppcheck-suppress uninitvar
write(x,"ab",2);
// cppcheck-suppress uninitvar
write(fd,buf,2);
// cppcheck-suppress uninitvar
write(fd,"ab",x);
}

View File

@ -3850,65 +3850,6 @@ private:
ASSERT_EQUALS("[test.cpp:6]: (debug) assertion failed '} while ('\n", errout.str());
}
void uninitvar_posix_write() { // #6325
// Load posix library file
LOAD_LIB_2(settings.library, "posix.cfg");
// check the first parameter of write
checkUninitVar("void uninitvar(char *buf)\n"
"{\n"
" int fd;\n"
" write(fd, buf, sizeof(buf));\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: fd\n", errout.str());
checkUninitVarB("void no_uninitvar(int fd, char *buf)\n"
"{\n"
" write(fd, buf, 8);\n"
"}");
ASSERT_EQUALS("", errout.str());
// check the second parameter of the posix function write
checkUninitVar("void uninitvar() {\n"
" char *buf;\n"
" write(STDOUT_FILENO, buf, sizeof(buf));\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: buf\n", errout.str());
checkUninitVar("void uninitvar() {\n"
" char buf[2];\n"
" write(STDOUT_FILENO, buf, 2);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: buf\n", errout.str());
// avoid false positives
checkUninitVarB("void no_uninitvar(char *buf) {\n"
" write(STDOUT_FILENO, buf, 8);\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVarB("void no_uninitvar() {\n"
" char buf[1] = {'c'};\n"
" write(STDOUT_FILENO, &buf, 1);\n"
"}");
ASSERT_EQUALS("", errout.str());
// check the third parameter of the posix function write
checkUninitVar2("void uninitvar(char *buf) {\n"
" int nbytes;\n"
" write(STDOUT_FILENO, buf, nbytes);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: nbytes\n", errout.str());
checkUninitVarB("void no_uninitvar(char *buf, int nbytes)\n"
"{\n"
" write(STDOUT_FILENO, buf, nbytes);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void checkDeadPointer(const char code[]) {
// Clear the error buffer..
errout.str("");