This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

Re: [v3] Fix stringbuf handling of NUL characters


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


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