You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I discovered these bugs while analyzing why the libcxx test std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp fails. (An assert fails because get() does not null-terminate when an exception is raised on EOF.)
libc++ and libstdc++ do not null-terminate as well when a streambuf member function or the sentry constructor throw. However, the standard mandates that the output buffer must be null-terminated "in any case". Moreover, there is additional language in [istream.unformatted]/1 that the output buffer must be null-terminated when the sentry constructor throws:
Otherwise, if the sentry constructor exits by throwing an exception or if the sentry object produces false, when converted to a value of type bool, the function returns without attempting to obtain any input. In either case the number of extracted characters is set to 0; unformatted input functions taking a character array of nonzero size as an argument shall also store a null character (using charT()) in the first location of the array.
The text was updated successfully, but these errors were encountered:
By the way, a strict reading of the quote from [istream.unformatted]/1 suggests that read() and readsome() should null-terminate as well when sentry fails. I think this doesn't make much sense, though, since these functions do not null-terminate their buffers in any other case.
Describe the bug
basic_stringstream::get[line]()
do not handle null-termination correctly:The standard says (N4993 [istream.unformatted]/9 and 21):
So the output buffer must always be null-terminated except if the buffer has size 0.
Test case
https://godbolt.org/z/zfKqnePGh
Expected behavior
The program should print
Actual behavior
The program actually prints
Additional remarks
I discovered these bugs while analyzing why the libcxx test std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp fails. (An assert fails because
get()
does not null-terminate when an exception is raised on EOF.)libc++ and libstdc++ do not null-terminate as well when a streambuf member function or the
sentry
constructor throw. However, the standard mandates that the output buffer must be null-terminated "in any case". Moreover, there is additional language in [istream.unformatted]/1 that the output buffer must be null-terminated when thesentry
constructor throws:The text was updated successfully, but these errors were encountered: