[v3] Fix stringbuf handling of NUL characters

Gabriel Dos Reis Gabriel.Dos-Reis@cmla.ens-cachan.fr
Thu Jul 12 23:50:00 GMT 2001


Phil Edwards <pedwards@disaster.jaj.com> writes:

| On Thu, Jul 12, 2001 at 10:32:15AM +0200, Gabriel Dos Reis wrote:
| > Andrew Snare <ASnare@allshare.nl> writes:
| > | 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.
| 
| Since we're talking about NUL characters in the middle of the data,
| I would argue that it's a meaningless distinction.

I don't think so.  Calling c_str() doesn't give the whole characters.

-- Gaby



More information about the Gcc-patches mailing list