aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/26_numerics
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-03-18 13:22:17 +0000
committerJonathan Wakely <jwakely@redhat.com>2024-03-19 15:59:44 +0000
commit07e03761a7fc1626a6a74ed957e117f56981558c (patch)
tree6b66bbf3ca7e2cc3331d1d2c83c20f580f198267 /libstdc++-v3/testsuite/26_numerics
parentc608b57f77a47179899666940c3b8b6a2e5435b2 (diff)
downloadgcc-07e03761a7fc1626a6a74ed957e117f56981558c.zip
gcc-07e03761a7fc1626a6a74ed957e117f56981558c.tar.gz
gcc-07e03761a7fc1626a6a74ed957e117f56981558c.tar.bz2
libstdc++: Fix infinite loop in std::binomial_distribution [PR114359]
The multiplication (4 * _M_t * __1p) can wraparound to zero if _M_t is unsigned and 4 * _M_t wraps to zero. The third operand has type double, so do the second multiplication first, so that we aren't multiplying integers. libstdc++-v3/ChangeLog: PR libstdc++/114359 * include/bits/random.tcc (binomial_distribution::param_type): Ensure arithmetic is done as type double. * testsuite/26_numerics/random/binomial_distribution/114359.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/26_numerics')
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc
new file mode 100644
index 0000000..c1e4c38
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/114359.cc
@@ -0,0 +1,12 @@
+// { dg-do run { target c++11 } }
+
+// Bug 114359 - std::binomial_distribution hangs in infinite loop
+
+#include <random>
+
+int main()
+{
+ std::default_random_engine g{};
+ std::binomial_distribution<std::uint32_t> b(1U << 30);
+ b(g); // hangs forever
+}