From d69788cec61a84025cdf6e05d8aaafc07a92b9e1 Mon Sep 17 00:00:00 2001 From: Artem Belevich Date: Tue, 3 Dec 2024 14:24:03 -0800 Subject: [PATCH] Fix value range overflows in tests `random_integers()` may generate values not representable as an integer type, which results in undefined behavior when we attempt to cast them to integer type later on. To avoid that, generate random numbers using the integer type we'll cast to later on, so we're guaranteed to have representable values. --- thrust/testing/for_each.cu | 4 ++-- thrust/testing/set_difference.cu | 2 +- thrust/testing/set_difference_by_key.cu | 2 +- thrust/testing/set_intersection.cu | 2 +- thrust/testing/set_intersection_by_key.cu | 2 +- thrust/testing/set_symmetric_difference.cu | 2 +- thrust/testing/set_symmetric_difference_by_key.cu | 2 +- thrust/testing/set_union_by_key.cu | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/thrust/testing/for_each.cu b/thrust/testing/for_each.cu index 5699c87e19a..86c36c673ab 100644 --- a/thrust/testing/for_each.cu +++ b/thrust/testing/for_each.cu @@ -167,7 +167,7 @@ void TestForEach(const size_t n) { const size_t output_size = std::min((size_t) 10, 2 * n); - thrust::host_vector h_input = unittest::random_integers(n); + thrust::host_vector h_input = unittest::random_integers(n); for (size_t i = 0; i < n; i++) { @@ -199,7 +199,7 @@ void TestForEachN(const size_t n) { const size_t output_size = std::min((size_t) 10, 2 * n); - thrust::host_vector h_input = unittest::random_integers(n); + thrust::host_vector h_input = unittest::random_integers(n); for (size_t i = 0; i < n; i++) { diff --git a/thrust/testing/set_difference.cu b/thrust/testing/set_difference.cu index 5fe1de1fc1e..0af2813d18a 100644 --- a/thrust/testing/set_difference.cu +++ b/thrust/testing/set_difference.cu @@ -134,7 +134,7 @@ DECLARE_VARIABLE_UNITTEST(TestSetDifferenceEquivalentRanges); template void TestSetDifferenceMultiset(const size_t n) { - thrust::host_vector vec = unittest::random_integers(2 * n); + thrust::host_vector vec = unittest::random_integers(2 * n); // restrict elements to [min,13) for (typename thrust::host_vector::iterator i = vec.begin(); i != vec.end(); ++i) diff --git a/thrust/testing/set_difference_by_key.cu b/thrust/testing/set_difference_by_key.cu index 085a0d66700..1ffe8a780f5 100644 --- a/thrust/testing/set_difference_by_key.cu +++ b/thrust/testing/set_difference_by_key.cu @@ -235,7 +235,7 @@ DECLARE_VARIABLE_UNITTEST(TestSetDifferenceByKeyEquivalentRanges); template void TestSetDifferenceByKeyMultiset(const size_t n) { - thrust::host_vector vec = unittest::random_integers(2 * n); + thrust::host_vector vec = unittest::random_integers(2 * n); // restrict elements to [min,13) for (typename thrust::host_vector::iterator i = vec.begin(); i != vec.end(); ++i) diff --git a/thrust/testing/set_intersection.cu b/thrust/testing/set_intersection.cu index af95e2cdf07..b312a30bd5b 100644 --- a/thrust/testing/set_intersection.cu +++ b/thrust/testing/set_intersection.cu @@ -168,7 +168,7 @@ DECLARE_VARIABLE_UNITTEST(TestSetIntersectionEquivalentRanges); template void TestSetIntersectionMultiset(const size_t n) { - thrust::host_vector vec = unittest::random_integers(2 * n); + thrust::host_vector vec = unittest::random_integers(2 * n); // restrict elements to [min,13) for (typename thrust::host_vector::iterator i = vec.begin(); i != vec.end(); ++i) diff --git a/thrust/testing/set_intersection_by_key.cu b/thrust/testing/set_intersection_by_key.cu index fae4837afd3..9c99e72377b 100644 --- a/thrust/testing/set_intersection_by_key.cu +++ b/thrust/testing/set_intersection_by_key.cu @@ -210,7 +210,7 @@ DECLARE_VARIABLE_UNITTEST(TestSetIntersectionByKeyEquivalentRanges); template void TestSetIntersectionByKeyMultiset(const size_t n) { - thrust::host_vector vec = unittest::random_integers(2 * n); + thrust::host_vector vec = unittest::random_integers(2 * n); // restrict elements to [min,13) for (typename thrust::host_vector::iterator i = vec.begin(); i != vec.end(); ++i) diff --git a/thrust/testing/set_symmetric_difference.cu b/thrust/testing/set_symmetric_difference.cu index 5b8f790b06b..7038165641a 100644 --- a/thrust/testing/set_symmetric_difference.cu +++ b/thrust/testing/set_symmetric_difference.cu @@ -134,7 +134,7 @@ DECLARE_VARIABLE_UNITTEST(TestSetSymmetricDifferenceEquivalentRanges); template void TestSetSymmetricDifferenceMultiset(const size_t n) { - thrust::host_vector vec = unittest::random_integers(2 * n); + thrust::host_vector vec = unittest::random_integers(2 * n); // restrict elements to [min,13) for (typename thrust::host_vector::iterator i = vec.begin(); i != vec.end(); ++i) diff --git a/thrust/testing/set_symmetric_difference_by_key.cu b/thrust/testing/set_symmetric_difference_by_key.cu index b5bde594fc4..ae82cec9414 100644 --- a/thrust/testing/set_symmetric_difference_by_key.cu +++ b/thrust/testing/set_symmetric_difference_by_key.cu @@ -234,7 +234,7 @@ DECLARE_VARIABLE_UNITTEST(TestSetSymmetricDifferenceByKeyEquivalentRanges); template void TestSetSymmetricDifferenceByKeyMultiset(const size_t n) { - thrust::host_vector vec = unittest::random_integers(2 * n); + thrust::host_vector vec = unittest::random_integers(2 * n); // restrict elements to [min,13) for (typename thrust::host_vector::iterator i = vec.begin(); i != vec.end(); ++i) diff --git a/thrust/testing/set_union_by_key.cu b/thrust/testing/set_union_by_key.cu index 85ac2dcbff5..b167517bbc4 100644 --- a/thrust/testing/set_union_by_key.cu +++ b/thrust/testing/set_union_by_key.cu @@ -234,7 +234,7 @@ DECLARE_VARIABLE_UNITTEST(TestSetUnionByKeyEquivalentRanges); template void TestSetUnionByKeyMultiset(const size_t n) { - thrust::host_vector vec = unittest::random_integers(2 * n); + thrust::host_vector vec = unittest::random_integers(2 * n); // restrict elements to [min,13) for (typename thrust::host_vector::iterator i = vec.begin(); i != vec.end(); ++i)