From fb91393bb205ea6a19cda4c92db5899519be9bdc Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Sun, 27 Sep 2015 16:25:43 -0700 Subject: [PATCH 1/3] Fixing size_t/int mismatch in loops. --- include/array_view.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/array_view.h b/include/array_view.h index e40918d..68a3cf0 100644 --- a/include/array_view.h +++ b/include/array_view.h @@ -1067,7 +1067,7 @@ public: } bounds_iterator& operator--() _NOEXCEPT { - for (int i = rank; i-- > 0;) + for (size_t i = rank; i-- > 0;) { if (curr[i]-- > 0) { @@ -1335,7 +1335,7 @@ namespace details auto extents = bnd.index_bounds(); typename Bounds::index_type stride; stride[Bounds::rank - 1] = 1; - for (int i = Bounds::rank - 2; i >= 0; --i) + for (size_t i = Bounds::rank - 2; i >= 0; --i) stride[i] = stride[i + 1] * extents[i + 1]; return stride; } @@ -2035,7 +2035,7 @@ private: fail_fast_assert(strides[rank - 1] == 1, "Only strided arrays with regular strides can be resized"); fail_fast_assert(strides[rank - 2] >= d && (strides[rank - 2] % d == 0), "The strides must have contiguous chunks of memory that can contain a multiple of new type elements"); - for (int i = rank - 2; i >= 0; --i) + for (size_t i = rank - 2; i >= 0; --i) { fail_fast_assert((strides[i] >= strides[i + 1]) && (strides[i] % strides[i + 1] == 0), "Only strided arrays with regular strides can be resized"); } From 99746e2d57a3068d1130dce4bf5b1e46a86cf9d2 Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Sun, 27 Sep 2015 16:53:58 -0700 Subject: [PATCH 2/3] Correct fix for int/size_t mismatch. --- include/array_view.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/include/array_view.h b/include/array_view.h index 68a3cf0..038b6e4 100644 --- a/include/array_view.h +++ b/include/array_view.h @@ -1328,15 +1328,15 @@ namespace details return bnd.strides(); } - // Make a stride vector from bounds, assuming continugous memory. + // Make a stride vector from bounds, assuming contiguous memory. template _CONSTEXPR std::enable_if_t::value, typename Bounds::index_type> make_stride(const Bounds& bnd) _NOEXCEPT { auto extents = bnd.index_bounds(); typename Bounds::index_type stride; stride[Bounds::rank - 1] = 1; - for (size_t i = Bounds::rank - 2; i >= 0; --i) - stride[i] = stride[i + 1] * extents[i + 1]; + for (size_t i = Bounds::rank - 1; Bounds::rank > 1 && i > 0; --i) + stride[i-1] = stride[i] * extents[i]; return stride; } @@ -2035,10 +2035,8 @@ private: fail_fast_assert(strides[rank - 1] == 1, "Only strided arrays with regular strides can be resized"); fail_fast_assert(strides[rank - 2] >= d && (strides[rank - 2] % d == 0), "The strides must have contiguous chunks of memory that can contain a multiple of new type elements"); - for (size_t i = rank - 2; i >= 0; --i) - { - fail_fast_assert((strides[i] >= strides[i + 1]) && (strides[i] % strides[i + 1] == 0), "Only strided arrays with regular strides can be resized"); - } + for (size_t i = rank - 1; i > 0; --i) + fail_fast_assert((strides[i-1] >= strides[i]) && (strides[i-1] % strides[i] == 0), "Only strided arrays with regular strides can be resized"); index_type ret = strides / d; ret[rank - 1] = 1; From bb169976da75c4c8a30b403ffc8ff887d72a75bf Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Sun, 27 Sep 2015 18:06:51 -0700 Subject: [PATCH 3/3] Fixed leak in owner<> test. Ha ha ha! --- tests/owner_tests.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/owner_tests.cpp b/tests/owner_tests.cpp index 430b31a..d985533 100644 --- a/tests/owner_tests.cpp +++ b/tests/owner_tests.cpp @@ -33,6 +33,7 @@ SUITE(owner_tests) CHECK(*p == 120); f(p); CHECK(*p == 121); + delete p; } }