This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Fix time_put::do_put for wchar_t
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 11 Mar 2002 01:05:30 +0100
- Subject: [v3] Fix time_put::do_put for wchar_t
Hi,
the below fixes a trivial buffer overflow which caused crash at run time of
time_put_members_wchar_t.cc. With it on linux-gnu we are down to 1 expected
failure:
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 have also removed a redundant variable introduced mistakenly yesterday.
Tested i686-pc-linux-gnu, approved by Benjamin Kosnik, committed.
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.
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- gcc/libstdc++-v3/include/bits/locale_facets.tcc 2002/03/09 16:44:34
1.70
+++ gcc/libstdc++-v3/include/bits/locale_facets.tcc 2002/03/10 23:51:31
1.71
@@ -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);