nth_element fix [58800]

Christopher Jefferson chris@bubblescope.net
Sat Oct 19 21:03:00 GMT 2013


A previous fix to a performance problem in std::sort unfortunately has
lead to a crashing bug in std::nth_element.

The following minimal patch fixes the problem (there are a couple of
different ways of fixing it, this is the shortest and safest).

2013-09-19 Chris Jefferson <chris@bubblescope.net>

PR libstdc++/58800
* include/bits/stl_algo.h (__unguarded_partition_pivot) : Change
__last - 2 to __last - 1, so we correctly work on arrays of length 4.
* testsuite/25_algorithms/nth_element/58800.cc : New
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nth_element1.patch
Type: application/octet-stream
Size: 2339 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20131019/ce0e78b1/attachment.obj>


More information about the Libstdc++ mailing list