[PATCH] libstdc++: Fix division by zero in std::sample

Jonathan Wakely jwakely@redhat.com
Mon Sep 21 15:01:34 GMT 2020


On 18/09/20 21:08 -0400, Patrick Palka via Libstdc++ wrote:
>This fixes a division by zero in the selection-sampling std::__search
>overload when the input range is empty (and hence __unsampled_sz is 0).
>
>Tested on x86_64-pc-linux-gnu.
>
>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          |  3 ++
> .../testsuite/25_algorithms/sample/3.cc       | 50 +++++++++++++++++++
> 2 files changed, 53 insertions(+)
> create mode 100644 libstdc++-v3/testsuite/25_algorithms/sample/3.cc

OK, thanks.




More information about the Libstdc++ mailing list