From 6fe6bcf50d27e7f7fa86c993f214e797551eeb8a Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Wed, 22 Feb 2023 21:29:07 -0300 Subject: [PATCH] [tests] Fixed possible bug with uint overflow. Signed-off-by: Viktor Govako --- coding/coding_tests/succinct_ef_test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/coding/coding_tests/succinct_ef_test.cpp b/coding/coding_tests/succinct_ef_test.cpp index 08da1d5115..cde4833a61 100644 --- a/coding/coding_tests/succinct_ef_test.cpp +++ b/coding/coding_tests/succinct_ef_test.cpp @@ -14,7 +14,8 @@ using namespace std; template vector GetUniformValues(size_t count) { - uniform_int_distribution randDist; + // Use max - 1 because succinct makes val + 1 encoding internals. + uniform_int_distribution randDist(0, numeric_limits::max() - 1); random_device randDevice; mt19937 randEngine(randDevice()); @@ -33,7 +34,8 @@ template vector GetNormalValues(size_t count, T mean) vector data(count); for (size_t i = 0; i < count; ++i) { - T constexpr const kMax = numeric_limits::max(); + // Use max - 1 because succinct makes val + 1 encoding internals. + T constexpr const kMax = numeric_limits::max() - 1; double d = round(randDist(randEngine)); if (d < 0) d = 0;