From 401f27b34f53a4e4300b6fb00b5acc925a990733 Mon Sep 17 00:00:00 2001 From: "akihiro.takagi" Date: Mon, 21 Aug 2023 11:07:14 +0900 Subject: [PATCH] Avoid address overflow (random_fill) --- test/test_utility.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_utility.h b/test/test_utility.h index 1b96140..960a970 100644 --- a/test/test_utility.h +++ b/test/test_utility.h @@ -14,25 +14,25 @@ template constexpr T max_of() { return std::numeric_limits::max( template <> constexpr uint8_t max_of() { return 255; } template -static void random_fill_(T* dst, int n, T minv = min_of(), T maxv = max_of()) +static void random_fill_(T* dst, size_t n, T minv = min_of(), T maxv = max_of()) { std::uniform_int_distribution dist(minv, maxv); - for (int i = 0; i < n; ++i) + for (size_t i = 0; i < n; ++i) dst[i] = dist(g_engine); } template <> -void random_fill_(uint8_t* dst, int n, uint8_t minv, uint8_t maxv) +void random_fill_(uint8_t* dst, size_t n, uint8_t minv, uint8_t maxv) { std::uniform_int_distribution dist(minv, maxv); - for (int i = 0; i < n; ++i) + for (size_t i = 0; i < n; ++i) dst[i] = static_cast(dist(g_engine)); } template static void random_fill_(sgm::HostImage& image, T minv = min_of(), T maxv = max_of()) { - random_fill_(image.ptr(), image.rows * image.step, minv, maxv); + random_fill_(image.ptr(), image.rows * (size_t)image.step, minv, maxv); } static void random_fill(sgm::HostImage& image)