PR libstdc++/68197 fail on negative iword/pword indices
commitaa9d9423caf3189c94113dd94b0b451de5251f60
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 May 2018 19:04:55 +0000 (2 19:04 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 May 2018 19:04:55 +0000 (2 19:04 +0000)
treedb7f0ac922b90a89aa4e0b2f32f85e5891399070
parentf1493596d02b9bc8eb3b96bd41d4351ebd50a282
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259854 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/ios_base.h
libstdc++-v3/src/c++11/ios.cc
libstdc++-v3/testsuite/27_io/ios_base/storage/68197.cc [new file with mode: 0644]