stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r405909 - /incubator/stdcxx/trunk/tests/src/char.cpp
Date Fri, 12 May 2006 22:37:49 GMT
Author: sebor
Date: Fri May 12 15:37:49 2006
New Revision: 405909

URL: http://svn.apache.org/viewcvs?rev=405909&view=rev
Log:
2006-05-12  Martin Sebor  <sebor@roguewave.com>

        * char.cpp (UChar): New convenience typedef.
        (_rw_expand, _rw_fmtstringv): Cast char to unsigned char before
        passing it to isdigit() in order to prevent undefined behavior
        caused by sign extension.

Modified:
    incubator/stdcxx/trunk/tests/src/char.cpp

Modified: incubator/stdcxx/trunk/tests/src/char.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/char.cpp?rev=405909&r1=405908&r2=405909&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/char.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/char.cpp Fri May 12 15:37:49 2006
@@ -36,6 +36,10 @@
 #include <stdlib.h>      // for strtol()
 #include <string.h>      // for memcpy(), strlen(), ...
 
+/**************************************************************************/
+// for convenience
+typedef unsigned char UChar;
+
 
 size_t
 UserTraits<UserChar>::
@@ -307,7 +311,7 @@
 
         unsigned long count;
 
-        if ('@' == psrc [1] && isdigit (psrc [2])) {
+        if ('@' == psrc [1] && isdigit (UChar (psrc [2]))) {
             // process directive
             psrc += 2;
 
@@ -361,8 +365,6 @@
             pnext = (char*)dst + buflen * elemsize;
         }
 
-        typedef unsigned char UChar;
-
         if (sizeof (WChar) == elemsize) {
             for (size_t i = 0; i != count; ++i)
                 ((WChar*)pnext)[i] = WChar (UChar (c));
@@ -466,8 +468,6 @@
         if (src) {
             // widen src into dst one element at a time
             for (size_t i = 0; ; ++i) {
-                typedef unsigned char UChar;
-
                 if (i == len) {
                     dst [i] = L'\0';
                     break;
@@ -517,8 +517,6 @@
         if (src) {
             // narrow src into dst one element at a time
             for (size_t i = 0; ; ++i) {
-                typedef unsigned char UChar;
-
                 if (i == len) {
                     dst [i] = '\0';
                     break;
@@ -565,8 +563,6 @@
         || _RWSTD_SIZE_MAX != len && memchr (s1, '@', len))
         s1 = rw_expand (s1_buf, s1, len, &s1_len);
 
-    typedef unsigned char UChar;
-
     size_t n = 0;
 
     for ( ; n != len && UChar (s1 [n]) == unsigned (s2 [n]); ++n) {
@@ -598,8 +594,6 @@
         if (src) {
             // widen src into dst one element at a time
             for (size_t i = 0; ; ++i) {
-                typedef unsigned char UChar;
-
                 if (i == len) {
                     dst [i] = UserChar::eos ();
                     break;
@@ -650,8 +644,6 @@
         if (src) {
             // narrow src into dst one element at a time
             for (size_t i = 0; ; ++i) {
-                typedef unsigned char UChar;
-
                 if (i == len) {
                     dst [i] = '\0';
                     break;
@@ -698,8 +690,6 @@
         || _RWSTD_SIZE_MAX != len && memchr (s1, '@', len))
         s1 = rw_expand (s1_buf, s1, len, &s1_len);
 
-    typedef unsigned char UChar;
-
     size_t n = 0;
 
     for ( ; n != len && UChar (s1 [n]) == s2 [n].c; ++n) {
@@ -772,7 +762,7 @@
         elemsize = va_arg (*pva, int);
         ++fmt;
     }
-    else if (isdigit (*fmt)) {
+    else if (isdigit (UChar (*fmt))) {
         // process positional parameter or width
         char* end = 0;
         const int arg = strtol (fmt, &end, 10);
@@ -800,7 +790,7 @@
             nelems = va_arg (*pva, int);
             ++fmt;
         }
-        else if (isdigit (*fmt)) {
+        else if (isdigit (UChar (*fmt))) {
             char* end = 0;
             nelems = int (strtol (fmt, &end, 10));
             fmt    = end;



Mime
View raw message