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]

Re: [PATCH/RFC] Fix interactive half of libstdc++/6745


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


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