[PATCH/RFC] Fix interactive half of libstdc++/6745
Gabriel Dos Reis
gdr@integrable-solutions.net
Mon Nov 18 08:57:00 GMT 2002
Paolo Carlini <pcarlini@rocketmail.com> writes:
| Hi everyone, hi Benjamin,
|
| Jonathan Lennox fixed the non-interactive half of the
| PR (and the related 8071, 8127) by adding code dealing
| with in_avail == 0 like this:
|
| ...
| else {
| _CharT __buf[256];
| streamsize __charsread = __sbin->sgetn(__buf,
| sizeof(__buf));
If this bit was already there in source, then I beleive it is
incorrect as sizeof(__buf) is 256 * sizeof (_CharT) which is not
necessarily 256 and we would get a buffer overrun :-(.
It should read either
__sbin->sgetn(__buf, sizeof (__buf) / sizeof (_CharT))
or
__sbin->sgetn(__buf, __array_length(__buf))
where __array_length() is a general utility written as
template<typename _Tp, std::size_t _Np>
inline std::size_t
__array_length(const _Tp (&)[_Np])
{ return _Np; }
-- Gaby
More information about the Libstdc++
mailing list