Merge pull request #486 from orbitcowboy/master

testuninitvar: moved more tests to checkUninitVar2
This commit is contained in:
Martin Ettl 2014-12-16 10:05:24 +01:00
commit 3686b22528
1 changed files with 97 additions and 97 deletions

View File

@ -2046,13 +2046,13 @@ private:
} }
void uninitvar_typeof() { void uninitvar_typeof() {
checkUninitVar("void f() {\n" checkUninitVar2("void f() {\n"
" struct Fred *fred;\n" " struct Fred *fred;\n"
" typeof(fred->x);\n" " typeof(fred->x);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n" checkUninitVar2("void f() {\n"
" struct SData * s;\n" " struct SData * s;\n"
" ab(typeof(s->status));\n" " ab(typeof(s->status));\n"
"}"); "}");
@ -3603,7 +3603,7 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str());
checkUninitVar("void f(FILE * pFile) {\n" checkUninitVar2("void f(FILE * pFile) {\n"
" clearerr (pFile);\n" " clearerr (pFile);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3615,7 +3615,7 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str());
checkUninitVar("void f(FILE * pFile) {\n" checkUninitVar2("void f(FILE * pFile) {\n"
" fclose (pFile);\n" " fclose (pFile);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3635,7 +3635,7 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: filename\n" ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: filename\n"
"[test.cpp:4]: (error) Uninitialized variable: mode\n", errout.str()); "[test.cpp:4]: (error) Uninitialized variable: mode\n", errout.str());
checkUninitVar("void f(FILE * name, char *mode) {\n" checkUninitVar2("void f(FILE * name, char *mode) {\n"
" fopen (name, mode);\n" " fopen (name, mode);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3647,7 +3647,7 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str());
checkUninitVar("void f(FILE * pFile) {\n" checkUninitVar2("void f(FILE * pFile) {\n"
" feof (pFile);\n" " feof (pFile);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3659,7 +3659,7 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str());
checkUninitVar("void f(FILE * pFile) {\n" checkUninitVar2("void f(FILE * pFile) {\n"
" ferror (pFile);\n" " ferror (pFile);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3671,7 +3671,7 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str());
checkUninitVar("void f(FILE * pFile) {\n" checkUninitVar2("void f(FILE * pFile) {\n"
" fflush (pFile);\n" " fflush (pFile);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3683,7 +3683,7 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: pFile\n", errout.str());
checkUninitVar("void f(FILE * pFile) {\n" checkUninitVar2("void f(FILE * pFile) {\n"
" fgetc (pFile);\n" " fgetc (pFile);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3698,13 +3698,13 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n" ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n"
"[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); "[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("void f(FILE * f) {\n" checkUninitVar2("void f(FILE * f) {\n"
" fpos_t p;" " fpos_t p;"
" fgetpos (f, &p);\n" " fgetpos (f, &p);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("void f(FILE * f, fpos_t *p) {\n" checkUninitVar2("void f(FILE * f, fpos_t *p) {\n"
" fgetpos (f, p);\n" " fgetpos (f, p);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3738,13 +3738,13 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: n\n" ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: n\n"
"[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str()); "[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar("void f(char * s, int n) {\n" checkUninitVar2("void f(char * s, int n) {\n"
" FILE *f;\n" " FILE *f;\n"
" fgets (s, n, f);\n" " fgets (s, n, f);\n"
"}"); "}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: f\n","", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: f\n","", errout.str());
checkUninitVar("void f(char * s, int n, FILE *f) {\n" checkUninitVar2("void f(char * s, int n, FILE *f) {\n"
" fgets (s, n, f);\n" " fgets (s, n, f);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3758,7 +3758,7 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n" ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n"
"[test.cpp:3]: (error) Uninitialized variable: f\n", errout.str()); "[test.cpp:3]: (error) Uninitialized variable: f\n", errout.str());
checkUninitVar("void f(int c, FILE *f) {\n" checkUninitVar2("void f(int c, FILE *f) {\n"
" fputc (c, f);\n" " fputc (c, f);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3772,7 +3772,7 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n" ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n"
"[test.cpp:3]: (error) Uninitialized variable: f\n", errout.str()); "[test.cpp:3]: (error) Uninitialized variable: f\n", errout.str());
checkUninitVar("void f(char *c, FILE *f) {\n" checkUninitVar2("void f(char *c, FILE *f) {\n"
" fputs (c, f);\n" " fputs (c, f);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3784,7 +3784,7 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: f\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: f\n", errout.str());
checkUninitVar("void f( FILE *f) {\n" checkUninitVar2("void f( FILE *f) {\n"
" ftell (f);\n" " ftell (f);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3796,41 +3796,41 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: c\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: c\n", errout.str());
checkUninitVar("void f( char *c) {\n" checkUninitVar2("void f( char *c) {\n"
" puts (c);\n" " puts (c);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// putchar // putchar
checkUninitVar("void f() {\n" checkUninitVar2("void f() {\n"
" char *c;" " char *c;"
" putchar (*c);\n" " putchar (*c);\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: c\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: c\n", errout.str());
checkUninitVar("void f( char *c) {\n" checkUninitVar2("void f( char *c) {\n"
" putchar (*c);\n" " putchar (*c);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #6116 False positive uninitvar - first argument to wcstombs() // #6116 False positive uninitvar - first argument to wcstombs()
checkUninitVar("void f( wchar_t *wstr) {\n" checkUninitVar2("void f( wchar_t *wstr) {\n"
" char buf[10];\n" " char buf[10];\n"
" wcstombs (buf, wstr, 3);\n" " wcstombs (buf, wstr, 3);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("void f( char *str) {\n" checkUninitVar2("void f( char *str) {\n"
" wchar_t wbuf[10];\n" " wchar_t wbuf[10];\n"
" mbstowcs (wbuf, str, 3);\n" " mbstowcs (wbuf, str, 3);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("void foo() {\n" checkUninitVar2("void foo() {\n"
" char buf[10];\n" " char buf[10];\n"
" tmpnam(buf);\n" " tmpnam(buf);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("void foo() {\n" checkUninitVar2("void foo() {\n"
" char *ptr;\n" " char *ptr;\n"
" tmpnam(ptr);\n" " tmpnam(ptr);\n"
"}"); "}");
@ -3893,9 +3893,9 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: fd\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: fd\n", errout.str());
checkUninitVar("void no_uninitvar(int fd, char *buf)\n" checkUninitVar2("void no_uninitvar(int fd, char *buf)\n"
"{\n" "{\n"
" write(fd, buf, sizeof(buf));\n" " write(fd, buf, 8);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3914,12 +3914,12 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: buf\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: buf\n", errout.str());
// avoid false positives // avoid false positives
checkUninitVar("void no_uninitvar(char *buf) {\n" checkUninitVar2("void no_uninitvar(char *buf) {\n"
" write(STDOUT_FILENO, buf, sizeof(buf));\n" " write(STDOUT_FILENO, buf, 8);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("void no_uninitvar() {\n" checkUninitVar2("void no_uninitvar() {\n"
" char buf[1] = {'c'};\n" " char buf[1] = {'c'};\n"
" write(STDOUT_FILENO, &buf, 1);\n" " write(STDOUT_FILENO, &buf, 1);\n"
"}"); "}");
@ -3927,13 +3927,13 @@ private:
// check the third parameter of the posix function write // check the third parameter of the posix function write
checkUninitVar("void uninitvar(char *buf) {\n" checkUninitVar2("void uninitvar(char *buf) {\n"
" int nbytes;\n" " int nbytes;\n"
" write(STDOUT_FILENO, buf, nbytes);\n" " write(STDOUT_FILENO, buf, nbytes);\n"
"}"); "}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: nbytes\n", "", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: nbytes\n", "", errout.str());
checkUninitVar("void no_uninitvar(char *buf, int nbytes)\n" checkUninitVar2("void no_uninitvar(char *buf, int nbytes)\n"
"{\n" "{\n"
" write(STDOUT_FILENO, buf, nbytes);\n" " write(STDOUT_FILENO, buf, nbytes);\n"
"}"); "}");