[patch] libstdc++/61086 - fix ubsan errors in std::vector
Jonathan Wakely
jwakely@redhat.com
Wed May 7 12:07:00 GMT 2014
The testcase in the PR calls __position._M_const_cast() to get a
mutable iterator and that dereferences the pointer as suggested in
http://gcc.gnu.org/ml/libstdc++/2013-05/msg00031.html
That's invalid because the pointer is not dereferenceable (in this
case it's null but is past-the-end at all times).
I played around with changing the __normal_iterator so we would do
__postition._M_const_cast(begin()) then decided we don't need it at
all and can just as easily obtain a mutable iterator using:
auto __pos = begin() + (__position - cbegin());
I plan to commit the attached patch to trunk and 4.9 soon. I've tested
it on x86_64-linux but not added a testcase because we don't test with
-fsanitize (though we should do) and it only shows up with Clang
anyway.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 7602 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20140507/5e8869a6/attachment.bin>
More information about the Libstdc++
mailing list