[Bug libstdc++/68197] negative index to ios_base::iword lead to unpredictable result
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed May 2 19:05:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68197
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Wed May 2 19:04:55 2018
New Revision: 259854
URL: https://gcc.gnu.org/viewcvs?rev=259854&root=gcc&view=rev
Log:
PR libstdc++/68197 fail on negative iword/pword indices
The suggested resolution of LWG 3083 is to make invalid indices
undefined, but we can fairly easily check for them and treat them as
errors in the same way as allocation failure. This avoids a segfault or
worse, setting an error flag on the stream instead.
PR libstdc++/68197
* include/bits/ios_base.h (ios_base::iword, ios_base::pword): Cast
indices to unsigned.
* src/c++11/ios.cc (ios_base::_M_grow_words): Treat negative indices
as failure. Refactor error handling.
* testsuite/27_io/ios_base/storage/68197.cc: New.
Added:
trunk/libstdc++-v3/testsuite/27_io/ios_base/storage/68197.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/bits/ios_base.h
trunk/libstdc++-v3/src/c++11/ios.cc
More information about the Gcc-bugs
mailing list