diff --git a/lib/checknonreentrantfunctions.h b/lib/checknonreentrantfunctions.h index c78f7132f..fb1fdc437 100644 --- a/lib/checknonreentrantfunctions.h +++ b/lib/checknonreentrantfunctions.h @@ -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" }; diff --git a/lib/checkobsoletefunctions.h b/lib/checkobsoletefunctions.h index b98ea06b3..fb1242bee 100644 --- a/lib/checkobsoletefunctions.h +++ b/lib/checkobsoletefunctions.h @@ -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)."; diff --git a/test/testnonreentrantfunctions.cpp b/test/testnonreentrantfunctions.cpp index 0fb2c1bb8..64fe77968 100644 --- a/test/testnonreentrantfunctions.cpp +++ b/test/testnonreentrantfunctions.cpp @@ -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()); }