This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] Fix stringbuf handling of NUL characters
- To: Andrew Snare <ASnare at allshare dot nl>
- Subject: Re: [v3] Fix stringbuf handling of NUL characters
- From: Gabriel Dos Reis <Gabriel dot Dos-Reis at cmla dot ens-cachan dot fr>
- Date: 12 Jul 2001 10:32:15 +0200
- Cc: Phil Edwards <pedwards at disaster dot jaj dot com>, libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, Mathew Pitchforth <mathew at pandromeda dot com>
- Organization: CMLA, ENS Cachan -- CNRS UMR 8536 (France)
- References: <5.1.0.14.0.20010712093301.0409cb80@10.1.3.1>
Andrew Snare <ASnare@allshare.nl> writes:
| >+ : __streambuf_type(), _M_string(__str.c_str(), __str.size())
| > { _M_stringbuf_init(__mode); }
| >
| > // Get and set:
|
| Just looking at this patch at face value, I would have thought that
| __str.data() would be better to use in this situation. Without referring
| to the exact wording of the standard, I would argue that the results of
| c_str() are undefined if the string contains NUL characters -- it does,
| after all, return a C-style string which is NUL-terminated (and thus
| one could argue nothing after that NUL is valid). On the other hand,
| data() specifically returns the string data as-is, and doesn't bother
| to NUL-terminate it.
Completely agreed.
Phil, with that change and appropriate testcases, your patch is OK for
mainline and branch.
Thanks to both of you.
-- Gaby