stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r604038 - in /incubator/stdcxx/trunk/tests: localization/22.locale.codecvt.length.cpp localization/22.locale.codecvt.out.cpp localization/22.locale.time.get.cpp localization/22.locale.time.put.cpp src/locale.cpp
Date Thu, 13 Dec 2007 21:35:00 GMT
Author: sebor
Date: Thu Dec 13 13:34:58 2007
New Revision: 604038

URL: http://svn.apache.org/viewvc?rev=604038&view=rev
Log:
2007-12-12  Travis Vitek  <vitek@roguewave.com>

	STDCXX-524
	* tests/localization/22.locale.codecvt.length.cpp (create_locale):
	Check return code from rw_snprintf().
	* tests/localization/22.locale.codecvt.out.cpp (create_locale):
	Ditto.
	* tests/localization/22.locale.time.get.cpp (make_LC_TIME):
	Ditto. Use rw_snprintf() instead of sprintf(), use larger
	fixed buffer sizes.
	* tests/localization/22.locale.time.put.cpp (make_LC_TIME):
	Ditto.
	* tests/src/locale.cpp (): Ditto.

Modified:
    incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.length.cpp
    incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.out.cpp
    incubator/stdcxx/trunk/tests/localization/22.locale.time.get.cpp
    incubator/stdcxx/trunk/tests/localization/22.locale.time.put.cpp
    incubator/stdcxx/trunk/tests/src/locale.cpp

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.length.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.length.cpp?rev=604038&r1=604037&r2=604038&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.length.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.length.cpp Thu Dec 13 13:34:58
2007
@@ -69,7 +69,9 @@
 const char* create_locale ()
 {
     char cm_fname [1024];
-    rw_sprintf (cm_fname, "%s%c%s", locale_root, _RWSTD_PATH_SEP, "charmap");
+    if (rw_snprintf (cm_fname, sizeof cm_fname, "%s%c%s",
+                     locale_root, _RWSTD_PATH_SEP, "charmap") < 0)
+        return 0;
 
     static const char charmap[] = {
         "<code_set_name> test_charmap\n"
@@ -98,7 +100,9 @@
         return 0;
 
     char src_fname [1024];
-    rw_sprintf (src_fname, "%s%c%s", locale_root, _RWSTD_PATH_SEP, "source");
+    if (rw_snprintf (src_fname, sizeof src_fname, "%s%c%s",
+                     locale_root, _RWSTD_PATH_SEP, "source") < 0)
+        return 0;
 
     if (std::size_t (-1) == rw_fwrite (src_fname, "LC_CTYPE\nEND LC_CTYPE\n"))
         return 0;

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.out.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.out.cpp?rev=604038&r1=604037&r2=604038&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.out.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.codecvt.out.cpp Thu Dec 13 13:34:58
2007
@@ -58,7 +58,9 @@
 create_locale ()
 {
     char cm_fname [1024];
-    std::sprintf (cm_fname, "%s%c%s", locale_root, _RWSTD_PATH_SEP, "charmap");
+    if (rw_snprintf (cm_fname, sizeof cm_fname, "%s%c%s",
+                     locale_root, _RWSTD_PATH_SEP, "charmap") < 0)
+        return 0;
 
     static const char charmap[] = {
         "<code_set_name> test_charmap \n"
@@ -90,7 +92,9 @@
         return 0;
 
     char src_fname [1024];
-    std::sprintf (src_fname, "%s%c%s", locale_root, _RWSTD_PATH_SEP, "source");
+    if (rw_snprintf (src_fname, sizeof src_fname, "%s%c%s",
+                     locale_root, _RWSTD_PATH_SEP, "source") < 0)
+        return 0;
 
     if (std::size_t (-1) == rw_fwrite (src_fname, "LC_CTYPE\nEND LC_CTYPE\n"))
         return 0;

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.time.get.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.time.get.cpp?rev=604038&r1=604037&r2=604038&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.time.get.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.time.get.cpp Thu Dec 13 13:34:58 2007
@@ -39,6 +39,7 @@
 #include <driver.h>      // for rw_test()
 #include <file.h>        // for rw_nextfd()
 #include <rw_locale.h>   // for rw_locales()
+#include <rw_printf.h>   // for rw_snprintf()
 
 /**************************************************************************/
 
@@ -1125,14 +1126,16 @@
 static const char*
 make_LC_TIME (const time_data *td)
 {
-    static char locnamebuf [L_tmpnam + 32];
+    static char locnamebuf [1024];
 
     if (*locnamebuf)
         return locnamebuf;
 
     // create a temporary locale definition file
-    char srcfname [L_tmpnam + 32];
-    std::sprintf (srcfname, "%s" SLASH "LC_TIME.src", locale_root);
+    char srcfname [1024];
+    if (rw_snprintf (srcfname, sizeof srcfname, "%s%c%s",
+                     locale_root, _RWSTD_PATH_SEP, "LC_TIME.src") < 0)
+        return 0;
 
     std::FILE *fout = std::fopen (srcfname, "w");
 
@@ -1265,8 +1268,10 @@
     std::fclose (fout);
 
     // create a temporary character map file
-    char cmfname [L_tmpnam + 32];
-    std::sprintf (cmfname, "%s" SLASH "pcs.cm", locale_root);
+    char cmfname [1024];
+    if (rw_snprintf (cmfname, sizeof cmfname, "%s%c%s",
+                     locale_root, _RWSTD_PATH_SEP, "LC_TIME.cm") < 0)
+        return 0;
 
     fout = std::fopen (cmfname, "w");
     pcs_write (fout, 0);
@@ -1276,6 +1281,9 @@
     // process the locale definition file and the character map
     const char* const locname =
         rw_localedef ("-w ", srcfname, cmfname, "test-locale");
+
+    if (locname && (strlen(locname) < sizeof locnamebuf))
+        std::strcpy (locnamebuf, locname);
 
     return locname;
 }

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.time.put.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.time.put.cpp?rev=604038&r1=604037&r2=604038&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.time.put.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.time.put.cpp Thu Dec 13 13:34:58 2007
@@ -41,6 +41,7 @@
 #include <environ.h>     // for rw_putenv()
 #include <file.h>        // for pcs_write(), ...
 #include <rw_locale.h>   // for rw_localedef(), ...
+#include <rw_printf.h>   // for rw_snprintf()
 #include <valcmp.h>      // for rw_strncmp()
 
 
@@ -55,10 +56,6 @@
 // set in main() instead of here to avoid Solaris 7 putenv() bug (PR #30017)
 const char* locale_root;
 
-#define LC_TIME_SRC        "LC_TIME.src"
-#define LC_TIME_CM         "LC_TIME.cm"
-#define TEST_LOCALE_NAME   "test.locale"
-
 /**************************************************************************/
 
 const char* narrow (char *dst, const char *src)
@@ -482,7 +479,7 @@
 
 const char* make_LC_TIME (const time_data *td)
 {
-    static char locnamebuf [256];
+    static char locnamebuf [1024];
 
     // assume `td' points to the same data as the first time
     // the function was called and reuse the same database
@@ -490,12 +487,12 @@
         return locnamebuf;
 
     // create a temporary locale definition file
-    char lc_time_src_path [256];
-    std::strcpy (lc_time_src_path, locale_root);
-    std::strcat (lc_time_src_path, SLASH);
-    std::strcat (lc_time_src_path, LC_TIME_SRC);
+    char srcfname [1024];
+    if (rw_snprintf (srcfname, sizeof srcfname, "%s%c%s",
+                     locale_root, _RWSTD_PATH_SEP, "LC_TIME.src") < 0)
+        return 0;
 
-    std::FILE *fout = std::fopen (lc_time_src_path, "w");
+    std::FILE *fout = std::fopen (srcfname, "w");
 
     std::fprintf (fout, "LC_TIME\n");
 
@@ -626,25 +623,25 @@
     std::fclose (fout);
 
     // create a temporary character map file
-    char lc_time_cm_path [256];
-    std::strcpy (lc_time_cm_path, locale_root);
-    std::strcat (lc_time_cm_path, SLASH);
-    std::strcat (lc_time_cm_path, LC_TIME_CM);
+    char cmfname [1024];
+    if (rw_snprintf (cmfname, sizeof cmfname, "%s%c%s",
+                     locale_root, _RWSTD_PATH_SEP, "LC_TIME.cm") < 0)
+        return 0;
 
-    fout = std::fopen (lc_time_cm_path, "w");
+    fout = std::fopen (cmfname, "w");
     pcs_write (fout, 0);
 
     std::fclose (fout);
 
     const char* const locname =
-        rw_localedef ("", lc_time_src_path, lc_time_cm_path, TEST_LOCALE_NAME);
+        rw_localedef ("", srcfname, cmfname, "test-locale");
 
-    if (locname)
+    if (locname && (strlen(locname) < sizeof locnamebuf))
         std::strcpy (locnamebuf, locname);
 
     // remove temporary files
-    std::remove (lc_time_cm_path);
-    std::remove (lc_time_src_path);
+    std::remove (cmfname);
+    std::remove (srcfname);
 
     return locname;
 }

Modified: incubator/stdcxx/trunk/tests/src/locale.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/locale.cpp?rev=604038&r1=604037&r2=604038&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/locale.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/locale.cpp Thu Dec 13 13:34:58 2007
@@ -35,6 +35,7 @@
 #include <environ.h>      // for rw_putenv()
 #include <file.h>         // for SHELL_RM_RF, rw_tmpnam
 #include <rw_process.h>   // for rw_system()
+#include <rw_printf.h>    // for rw_snprintf()
 #include <driver.h>       // for rw_error()
 
 #ifdef _RWSTD_OS_LINUX
@@ -773,7 +774,10 @@
     // create a temporary locale definition file that exercises as
     // many different parts of the collate standard as possible
     char srcfname [PATH_MAX];
-    sprintf (srcfname, "%s%slocale.src", locale_root, SLASH);
+    if (rw_snprintf (srcfname, PATH_MAX, "%s%slocale.src",
+                     locale_root, SLASH) < 0) {
+        return 0;
+    }
 
     FILE *fout = fopen (srcfname, "w");
 
@@ -789,7 +793,10 @@
 
     // create a temporary character map file
     char cmfname [PATH_MAX];
-    sprintf (cmfname, "%s%scharmap.src", locale_root, SLASH);
+    if (rw_snprintf (cmfname, PATH_MAX, "%s%scharmap.src",
+                     locale_root, SLASH) < 0) {
+        return 0;
+    }
 
     fout = fopen (cmfname, "w");
 
@@ -799,11 +806,11 @@
         return 0;
     }
 
-       fprintf (fout, "%s", charmap);
+    fprintf (fout, "%s", charmap);
 
     fclose (fout);
 
-       locname = "test-locale";
+    locname = "test-locale";
 
     // process the locale definition file and character map
     if (0 == rw_localedef ("-w", srcfname, cmfname, locname))



Mime
View raw message