libstdc++: Fix division by zero in std::sample
authorPatrick Palka <ppalka@redhat.com>
Tue, 22 Sep 2020 00:48:23 +0000 (20:48 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 22 Sep 2020 00:48:23 +0000 (20:48 -0400)
commit813ad9c4dd5a779f12ad2abf710c6e75a3117ef0
treeeb59e04eaa2006f8861caf593bab2d6f3f44eda8
parentf017952d31ba8fa965106505bed5844cc1a63b4b
libstdc++: Fix division by zero in std::sample

This fixes a division by zero in the selection-sampling std::__sample
overload when the input range is empty (and hence __unsampled_sz is 0).

libstdc++-v3/ChangeLog:

* include/bits/stl_algo.h (__sample): Exit early when the
input range is empty.
* testsuite/25_algorithms/sample/3.cc: New test.
libstdc++-v3/include/bits/stl_algo.h
libstdc++-v3/testsuite/25_algorithms/sample/3.cc [new file with mode: 0644]