This is the mail archive of the gcc-bugs@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: defect in STL string


> I found a possible defect in the STL <string> template.

Thanks for your bug report. I believe the bug is in your code, and not
in gcc. When inserting std::ends into the strstream, a null byte is
appended to the stream.

When extracting a std::string from a stream, extraction shall continue
until one of the following conditions occur:
- n characters are stored;
- end­of­file occurs on the input sequence;
- isspace(c,getloc()) is true for the next available input character
  c.
(See 21.3.7.9/1 for the exact wording; n is either is.width() or
str.max_size())

Since isspace('\0') is false, the zero character is appended to s3,
giving a total length of six characters for s3. Since the null
character is not printing, you won't see it in the output.

Hope this helps,
Martin


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