From 930d96f68419342080d3b282bce397838f7649a6 Mon Sep 17 00:00:00 2001 From: Vitaliy Lyudvichenko Date: Wed, 29 Jun 2016 19:50:51 +0300 Subject: [PATCH] Fixing of AutoBuffer::allocate(nsz) method AutoBuffer::allocate(nsz) didn't work properly when (sz < nsz < fixed_size). In this case sz remained unchanged. --- modules/core/include/opencv2/core/utility.hpp | 2 +- modules/core/test/test_utils.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index 60b2d3a064..7e7a8b2b51 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -817,10 +817,10 @@ AutoBuffer<_Tp, fixed_size>::allocate(size_t _size) return; } deallocate(); + sz = _size; if(_size > fixed_size) { ptr = new _Tp[_size]; - sz = _size; } } diff --git a/modules/core/test/test_utils.cpp b/modules/core/test/test_utils.cpp index 18b0a5a7ea..a527ba6f28 100644 --- a/modules/core/test/test_utils.cpp +++ b/modules/core/test/test_utils.cpp @@ -27,6 +27,7 @@ TEST(CommandLineParser, testFailure) parser.get("h"); EXPECT_FALSE(parser.check()); } + TEST(CommandLineParser, testHas_noValues) { const char* argv[] = {"", "-h", "--info"}; @@ -218,4 +219,17 @@ TEST(CommandLineParser, positional_regression_5074_equal_sign) EXPECT_TRUE(parser.check()); } + +TEST(AutoBuffer, allocate_test) +{ + AutoBuffer abuf(2); + EXPECT_EQ(2, abuf.size()); + + abuf.allocate(4); + EXPECT_EQ(4, abuf.size()); + + abuf.allocate(6); + EXPECT_EQ(6, abuf.size()); +} + } // namespace -- GitLab