[v3] Fix stringbuf handling of NUL characters
Gabriel Dos Reis
Gabriel.Dos-Reis@cmla.ens-cachan.fr
Thu Jul 12 01:32:00 GMT 2001
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
More information about the Gcc-patches
mailing list