TestUninitVar: move out posix.cfg testing
This commit is contained in:
parent
e9663873e5
commit
e5c098c7de
|
@ -441,6 +441,7 @@
|
||||||
</arg>
|
</arg>
|
||||||
</function>
|
</function>
|
||||||
<function name="write">
|
<function name="write">
|
||||||
|
<noreturn>false</noreturn>
|
||||||
<arg nr="1">
|
<arg nr="1">
|
||||||
<not-uninit/>
|
<not-uninit/>
|
||||||
</arg>
|
</arg>
|
||||||
|
|
|
@ -114,3 +114,14 @@ void invalidFunctionArg() {
|
||||||
// cppcheck-suppress invalidFunctionArg
|
// cppcheck-suppress invalidFunctionArg
|
||||||
usleep(1000000);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -3850,65 +3850,6 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (debug) assertion failed '} while ('\n", errout.str());
|
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[]) {
|
void checkDeadPointer(const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
Loading…
Reference in New Issue