Skip to content

Commit

Permalink
Fixing of AutoBuffer::allocate(nsz) method
Browse files Browse the repository at this point in the history
AutoBuffer::allocate(nsz) didn't work properly when
(sz < nsz < fixed_size). In this case sz remained unchanged.
  • Loading branch information
Vitaliy Lyudvichenko committed Jun 29, 2016
1 parent 69bd6da commit 930d96f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/core/include/opencv2/core/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
14 changes: 14 additions & 0 deletions modules/core/test/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TEST(CommandLineParser, testFailure)
parser.get<bool>("h");
EXPECT_FALSE(parser.check());
}

TEST(CommandLineParser, testHas_noValues)
{
const char* argv[] = {"<bin>", "-h", "--info"};
Expand Down Expand Up @@ -218,4 +219,17 @@ TEST(CommandLineParser, positional_regression_5074_equal_sign)
EXPECT_TRUE(parser.check());
}


TEST(AutoBuffer, allocate_test)
{
AutoBuffer<int, 5> abuf(2);
EXPECT_EQ(2, abuf.size());

abuf.allocate(4);
EXPECT_EQ(4, abuf.size());

abuf.allocate(6);
EXPECT_EQ(6, abuf.size());
}

} // namespace

0 comments on commit 930d96f

Please sign in to comment.