Fix ticket #3483 (POSIX.1-2008 - obsolete functions)

From POSIX.1-2008 specification (see http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap01.html#tag_22_01_01_04):
- remove obsolete functions ctime, asctime, rand, tmpnam (non reentrant functions check)
- add obsolete base functions (obsolete functions check):
 - rand_r
 - tmpnam, tmpnam_r
 - utime
 - asctime, asctime_r
 - ctime, ctime_r
- update unit tests (non reentrant function)
- update messages (cosmetic) (obsolete functions check)
This commit is contained in:
seb777 2012-01-12 22:28:12 +01:00
parent da09adc583
commit 8754caa36d
3 changed files with 30 additions and 14 deletions

View File

@ -63,10 +63,10 @@ private:
/** init nonreentrant functions list ' */
void initNonReentrantFunctions() {
static const char * const non_reentrant_functions_list[] = {
"ctime", "localtime", "gmtime", "asctime", "strtok", "gethostbyname", "gethostbyaddr", "getservbyname"
, "getservbyport", "crypt", "ttyname", "rand", "gethostbyname2"
"localtime", "gmtime", "strtok", "gethostbyname", "gethostbyaddr", "getservbyname"
, "getservbyport", "crypt", "ttyname", "gethostbyname2"
, "getprotobyname", "getnetbyname", "getnetbyaddr", "getrpcbyname", "getrpcbynumber", "getrpcent"
, "ctermid", "tmpnam", "readdir", "getlogin", "getpwent", "getpwnam", "getpwuid", "getspent"
, "ctermid", "readdir", "getlogin", "getpwent", "getpwnam", "getpwuid", "getspent"
, "fgetspent", "getspnam", "getgrnam", "getgrgid", "getnetgrent", "tempnam", "fgetpwent"
, "fgetgrent", "ecvt", "gcvt", "getservent", "gethostent", "getgrent", "fcvt"
};

View File

@ -94,17 +94,33 @@ private:
_obsoletePosixFunctions["rindex"] = "Found obsolete function 'rindex'. It is recommended to use the function 'strrchr' instead";
_obsoletePosixFunctions["pthread_attr_getstackaddr"] = "Found obsolete function 'pthread_attr_getstackaddr'.It is recommended that new applications use the 'pthread_attr_getstack' function";
_obsoletePosixFunctions["pthread_attr_setstackaddr"] = "Found obsolete function 'pthread_attr_setstackaddr'.It is recommended that new applications use the 'pthread_attr_setstack' function";
_obsoletePosixFunctions["pthread_attr_getstackaddr"] = "Found obsolete function 'pthread_attr_getstackaddr'. It is recommended that new applications use the 'pthread_attr_getstack' function";
_obsoletePosixFunctions["pthread_attr_setstackaddr"] = "Found obsolete function 'pthread_attr_setstackaddr'. It is recommended that new applications use the 'pthread_attr_setstack' function";
_obsoletePosixFunctions["scalbln"] = "Found obsolete function 'scalb'.It is recommended to use either 'scalbln', 'scalblnf' or 'scalblnl' instead of this function";
_obsoletePosixFunctions["scalbln"] = "Found obsolete function 'scalb'. It is recommended to use either 'scalbln', 'scalblnf' or 'scalblnl' instead of this function";
_obsoletePosixFunctions["ualarm"] = "Found obsolete function 'ualarm'.It is recommended to use either 'timer_create', 'timer_delete', 'timer_getoverrun', 'timer_gettime', or 'timer_settime' instead of this function";
_obsoletePosixFunctions["ualarm"] = "Found obsolete function 'ualarm'. It is recommended to use either 'timer_create', 'timer_delete', 'timer_getoverrun', 'timer_gettime', or 'timer_settime' instead of this function";
_obsoletePosixFunctions["vfork"] = "Found obsolete function 'vfork'. It is recommended to use the function 'fork' instead";
_obsoletePosixFunctions["wcswcs"] = "Found obsolete function 'wcswcs'. It is recommended to use the function 'wcsstr' instead";
_obsoletePosixFunctions["rand_r"] = "Found obsolete function 'rand_r'. It is recommended to use the function 'rand' instead";
_obsoletePosixFunctions["tmpnam"] = "Found obsolete function 'tmpnam'. It is recommended to use either 'tmpfile', 'mkstemp', or 'mkdtemp' instead for this function";
_obsoletePosixFunctions["tmpnam_r"] = "Found obsolete function 'tmpnam_r'. It is recommended to use either 'tmpfile', 'mkstemp', or 'mkdtemp' instead for this function";
_obsoletePosixFunctions["utime"] = "Found obsolete function 'utime'. It is recommended to use the function 'utimensat' instead";
_obsoletePosixFunctions["asctime"] = "Found obsolete function 'asctime'. It is recommended to use the function 'strftime' instead";
_obsoletePosixFunctions["asctime_r"] = "Found obsolete function 'asctime_r'. It is recommended to use the function 'strftime' instead";
_obsoletePosixFunctions["ctime"] = "Found obsolete function 'ctime'. It is recommended to use the function 'strftime' instead";
_obsoletePosixFunctions["ctime_r"] = "Found obsolete function 'ctime'. It is recommended to use the function 'strftime' instead";
_obsoleteStandardFunctions["gets"] = "Found obsolete function 'gets'. It is recommended to use the function 'fgets' instead\n"
"Found obsolete function 'gets'. With gets you'll get buffer overruns if the input data too big for the buffer. It is recommended to use the function 'fgets' instead.";
_obsoleteC99Functions["alloca"] = "Found obsolete function 'alloca'. It is recommended to use a variable length array.\nFound obsolete function 'alloca'. It is recommended to use a variable length array or a dynamically allocated array. The function 'alloca' is dangerous for many reasons (http://stackoverflow.com/questions/1018853/why-is-alloca-not-considered-good-practice and http://linux.die.net/man/3/alloca).";

View File

@ -91,9 +91,9 @@ private:
// Passed as function argument
check("int f()\n"
"{\n"
" printf(\"Magic guess: %d\n\", rand());\n"
" printf(\"Magic guess: %d\n\", getpwent());\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (portability) Found non reentrant function 'rand'. For threadsafe applications it is recommended to use the reentrant replacement function 'rand_r'\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (portability) Found non reentrant function 'getpwent'. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'\n", errout.str());
// Pass return value
check("int f()\n"
@ -106,12 +106,12 @@ private:
// Access via global namespace
check("int f()\n"
"{\n"
" ::rand();\n"
" ::getpwent();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (portability) Found non reentrant function 'rand'. For threadsafe applications it is recommended to use the reentrant replacement function 'rand_r'\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (portability) Found non reentrant function 'getpwent'. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'\n", errout.str());
// Be quiet on function definitions
check("int rand()\n"
check("int getpwent()\n"
"{\n"
" return 123;\n"
"}\n");
@ -120,14 +120,14 @@ private:
// Be quiet on other namespaces
check("int f()\n"
"{\n"
" foobar::rand();\n"
" foobar::getpwent();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// Be quiet on class member functions
check("int f()\n"
"{\n"
" foobar.rand();\n"
" foobar.getpwent();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}