This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix time_put::do_put for wchar_t


Hi,

I have nailed down the reason of the run time seg fault of
time_put_members_wchar_t.cc to a trivial buffer overflow: in time_put::do_put
the size in bytes of the buffer was not rescaled for sizeof(char_type) thus
resulting in a buffer typically 1/4 in size for wchar_t vs char. Fixed thusly,
and now on Linux we are down to 1 expected failure (double yeah!):

FAIL: 26_numerics/c99_classification_macros_c.cc (test for excess errors)

                === libstdc++-v3 Summary ===

# of expected passes            358
# of unexpected failures        1
# of unexpected successes       24
# of expected failures          1

I took also the occasion to remove from collate::do_transform a redundant
variable which I inadvertently introduced yesterday.

Tested i686-pc-linux-gnu, OK head and 3_1 ?

Ciao, Paolo.

//////////////

2002-03-10  Paolo Carlini  <pcarlini@unitus.it>

        * include/bits/locale_facets.tcc (time_put::do_put):
        Consider sizeof(char_type) in allocating the buffer.

        * include/bits/locale_facets.tcc (collate::do_tranform):
        Remove redundant variable.

--- locale_facets.tcc.~1.70.~ Sat Mar  9 12:46:34 2002
+++ locale_facets.tcc Sun Mar 10 16:50:15 2002
@@ -1795,7 +1795,8 @@
       // NB: This size is arbitrary. Should this be a data member,
       // initialized at construction?
       const size_t __maxlen = 64;
-      char_type* __res = static_cast<char_type*>(__builtin_alloca(__maxlen));
+      char_type* __res =
+ static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen));

       // NB: In IEE 1003.1-200x, and perhaps other locale models, it
       // is possible that the format character will be longer than one
@@ -1856,14 +1857,15 @@
     {
       size_t __len = (__hi - __lo) * 2;
       // First try a buffer perhaps big enough.
-      _CharT* __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) *
__len));
+      _CharT* __c =
+ static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len));
       size_t __res = _M_transform_helper(__c, __lo, __len);
       // If the buffer was not large enough, try again with the correct size.
       if (__res >= __len)
  {
    _CharT* __c2 =
      static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__res + 1)));
-   size_t __res2 = _M_transform_helper(__c2, __lo, __res + 1);
+   _M_transform_helper(__c2, __lo, __res + 1);
    return string_type(__c2);
  }
       return string_type(__c);



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]