This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[PATCH] Consistently use sizeof() in __builtin_alloca
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Sun, 31 Mar 2002 12:52:34 +0200
- Subject: [PATCH] Consistently use sizeof() in __builtin_alloca
Hi,
as Rth taught me there are a few machines around with
1750a/1750a.h:#define BITS_PER_UNIT 16
c4x/c4x.h:#define BITS_PER_UNIT 32
dsp16xx/dsp16xx.h:#define BITS_PER_UNIT 16
and, anyway, consistency imposes always using sizeof in char alloca.
Fixed with the below, tested i686-pc-linux-gnu. Ok?
Ciao,
Paolo.
////////////
2002-03-31 Paolo Carlini <pcarlini@unitus.it>
* include/bits/locale_facets.tcc (num_put::_M_convert_float ,
num_put::_M_convert_int): Consistently use sizeof() in alloca.
* include/bits/fstream.tcc (basic_filebuf::underflow,
basic_filebuf::_M_convert_to_external): Ditto.
* include/bits/ostream.tcc (operator<<(char __c),
operator<<(const char* __s)): Ditto.
--- fstream.tcc.~1.25.~ 2002-02-16 20:33:43.000000000 +0100
+++ fstream.tcc 2002-03-31 12:28:43.000000000 +0200
@@ -292,7 +292,8 @@
}
else
{
- char* __buf = static_cast<char*>(__builtin_alloca(_M_buf_size));
+ char* __buf =
+ static_cast<char*>(__builtin_alloca(sizeof(char) *
_M_buf_size));
__elen = _M_file->xsgetn(__buf, _M_buf_size);
const char* __eend;
@@ -447,7 +448,7 @@
if (__ext_multiplier == -1 || __ext_multiplier == 0)
__ext_multiplier = sizeof(char_type);
streamsize __blen = __ilen * __ext_multiplier;
- char* __buf = static_cast<char*>(__builtin_alloca(__blen));
+ char* __buf = static_cast<char*>(__builtin_alloca(sizeof(char) *
__blen));
char* __bend;
const char_type* __iend;
__res_type __r = __cvt.out(_M_state_cur, __ibuf, __ibuf + __ilen,
--- locale_facets.tcc.~1.73.~ 2002-03-19 21:59:38.000000000 +0100
+++ locale_facets.tcc 2002-03-31 12:20:22.000000000 +0200
@@ -625,7 +625,7 @@
// First try a buffer perhaps big enough (for sure sufficient for
// non-ios_base::fixed outputs)
int __cs_size = __max_digits * 3;
- char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
+ char* __cs = static_cast<char*>(__builtin_alloca(sizeof(char) *
__cs_size));
const bool __fp = _S_format_float(__io, __fbuf, __mod, __prec);
if (__fp)
@@ -637,7 +637,7 @@
if (__len >= __cs_size)
{
__cs_size = __len + 1;
- __cs = static_cast<char*>(__builtin_alloca(__cs_size));
+ __cs = static_cast<char*>(__builtin_alloca(sizeof(char) *
__cs_size));
if (__fp)
__len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
_S_c_locale, __prec);
else
@@ -654,7 +654,7 @@
// are largely sufficient.
const int __cs_size = __fixed ? __max_exp + __max_digits + 4
: __max_digits * 3;
- char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
+ char* __cs = static_cast<char*>(__builtin_alloca(sizeof(char) *
__cs_size));
if (_S_format_float(__io, __fbuf, __mod, __prec))
__len = __convert_from_v(__cs, 0, __fbuf, __v, _S_c_locale, __prec);
@@ -679,13 +679,13 @@
#ifdef _GLIBCPP_USE_C99
// First try a buffer perhaps big enough.
int __cs_size = 64;
- char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
+ char* __cs = static_cast<char*>(__builtin_alloca(sizeof(char) *
__cs_size));
int __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
_S_c_locale);
// If the buffer was not large enough, try again with the correct size.
if (__len >= __cs_size)
{
__cs_size = __len + 1;
- __cs = static_cast<char*>(__builtin_alloca(__cs_size));
+ __cs = static_cast<char*>(__builtin_alloca(sizeof(char) *
__cs_size));
__len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
_S_c_locale);
}
#else
--- ostream.tcc.~1.24.~ 2002-03-28 12:54:39.000000000 +0100
+++ ostream.tcc 2002-03-31 12:29:54.000000000 +0200
@@ -516,7 +516,8 @@
try
{
streamsize __w = __out.width();
- char* __pads = static_cast<char*>(__builtin_alloca(__w + 1));
+ char* __pads =
+ static_cast<char*>(__builtin_alloca(sizeof(char) * (__w + 1)));
__pads[0] = __c;
streamsize __len = 1;
if (__w > __len)
@@ -631,7 +632,7 @@
try
{
streamsize __w = __out.width();
- char* __pads = static_cast<char*>(__builtin_alloca(__w));
+ char* __pads =
static_cast<char*>(__builtin_alloca(sizeof(char) * __w));
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len)
{