[Bug libstdc++/68197] negative index to ios_base::iword lead to unpredictable result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68197 Jonathan Wakely changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED Target Milestone|--- |9.0 --- Comment #7 from Jonathan Wakely --- GCC 9 will set badbit in the stream state on invalid indices.
[Bug libstdc++/68197] negative index to ios_base::iword lead to unpredictable result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68197 --- Comment #6 from Jonathan Wakely --- Author: redi Date: Wed May 2 19:04:55 2018 New Revision: 259854 URL: https://gcc.gnu.org/viewcvs?rev=259854=gcc=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
[Bug libstdc++/68197] negative index to ios_base::iword lead to unpredictable result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68197 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2018-03-16 Ever confirmed|0 |1 --- Comment #5 from Jonathan Wakely --- I'v asked for this to be clarified in the standard, but in the meanwhile we should just report a failure for negative indices.
[Bug libstdc++/68197] negative index to ios_base::iword lead to unpredictable result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68197 --- Comment #4 from Christophe Monat --- (In reply to Jonathan Wakely from comment #3) > No, it seems underspecified. I have raised it with the C++ committee. Do you have feedback from the C++ committee ? I have only easily access to a 2011 standard, and reading 27.5.3.5 (3) : Returns : '(snip)... on failure, a valid long& initialized to 0'. I may be wrong, but I read this as an obligation to return 0 in the case described by Mickael.
[Bug libstdc++/68197] negative index to ios_base::iword lead to unpredictable result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68197 --- Comment #3 from Jonathan Wakely --- No, it seems underspecified. I have raised it with the C++ committee.
[Bug libstdc++/68197] negative index to ios_base::iword lead to unpredictable result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68197 --- Comment #2 from Mickael Guene --- Anyway it's a bad usage since index must come from xalloc. I was unable to find what the specifications say in case of using a negative index (or invalid index), do you have some inputs in this case ?
[Bug libstdc++/68197] negative index to ios_base::iword lead to unpredictable result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68197 --- Comment #1 from Jonathan Wakely --- I would argue that your program has undefined behaviour, there is no array element at a negative index.