testrunner: return value in non-void functions

This commit is contained in:
Daniel Marjamäki 2021-06-12 16:43:48 +02:00
parent 83d406806f
commit 118ad67645
1 changed files with 19 additions and 15 deletions

View File

@ -141,11 +141,12 @@ private:
void prohibitedFunctions_index() {
check("namespace n1 {\n"
" int index(){};\n"
" int index(){ return 1; };\n"
"}\n"
"int main()\n"
"{\n"
" n1::index();\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
@ -303,11 +304,12 @@ private:
"{\n"
" char s [ 10 ] ;\n"
" gets ( s ) ;\n"
" return 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str());
check("int getcontext(ucontext_t *ucp);\n"
"int f (ucontext_t *ucp)\n"
"void f (ucontext_t *ucp)\n"
"{\n"
" getcontext ( ucp ) ;\n"
"}");
@ -320,6 +322,7 @@ private:
"{\n"
" char s [ 10 ] ;\n"
" gets ( s ) ;\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
@ -351,7 +354,7 @@ private:
}
void prohibitedFunctions_namespaceHandling() {
check("int f()\n"
check("void f()\n"
"{\n"
" time_t t = 0;"
" std::localtime(&t);\n"
@ -359,14 +362,14 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str());
// Passed as function argument
check("int f()\n"
check("void f()\n"
"{\n"
" printf(\"Magic guess: %d\", getpwent());\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str());
// Pass return value
check("int f()\n"
check("void f()\n"
"{\n"
" time_t t = 0;"
" struct tm *foo = localtime(&t);\n"
@ -374,7 +377,7 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str());
// Access via global namespace
check("int f()\n"
check("void f()\n"
"{\n"
" ::getpwent();\n"
"}");
@ -389,14 +392,14 @@ private:
ASSERT_EQUALS("", errout.str());
// Be quiet on other namespaces
check("int f()\n"
check("void f()\n"
"{\n"
" foobar::getpwent();\n"
"}");
ASSERT_EQUALS("", errout.str());
// Be quiet on class member functions
check("int f()\n"
check("void f()\n"
"{\n"
" foobar.getpwent();\n"
"}");
@ -404,19 +407,19 @@ private:
}
void invalidFunctionUsage1() {
check("int f() { memset(a,b,sizeof(a)!=12); }");
check("void f() { memset(a,b,sizeof(a)!=12); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
check("int f() { memset(a,b,sizeof(a)!=0); }");
check("void f() { memset(a,b,sizeof(a)!=0); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
check("int f() { memset(a,b,!c); }");
check("void f() { memset(a,b,!c); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
// Ticket #6990
check("int f(bool c) { memset(a,b,c); }");
check("void f(bool c) { memset(a,b,c); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
check("int f() { memset(a,b,true); }");
check("void f() { memset(a,b,true); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
// Ticket #6588 (c mode)
@ -443,10 +446,10 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'.\n", errout.str());
check("int f() { strtol(a,b,1); }");
check("void f() { strtol(a,b,1); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'.\n", errout.str());
check("int f() { strtol(a,b,10); }");
check("void f() { strtol(a,b,10); }");
ASSERT_EQUALS("", errout.str());
}
@ -1210,6 +1213,7 @@ private:
" teststruct TestStruct1;\n"
" TestStruct1.testfunc1();\n"
" TestStruct1.testfunc2();\n"
" return 0;\n"
"}", "test.cpp", &settings2);
ASSERT_EQUALS("[test.cpp:4]: (warning) Return value of function testfunc1() is not used.\n"
"[test.cpp:4]: (warning) Return value of function testfunc2() is not used.\n"