Commit 930d96f6 authored by Vitaliy Lyudvichenko's avatar Vitaliy Lyudvichenko

Fixing of AutoBuffer::allocate(nsz) method

AutoBuffer::allocate(nsz) didn't work properly when
(sz < nsz < fixed_size). In this case sz remained unchanged.
parent 69bd6dad
...@@ -817,10 +817,10 @@ AutoBuffer<_Tp, fixed_size>::allocate(size_t _size) ...@@ -817,10 +817,10 @@ AutoBuffer<_Tp, fixed_size>::allocate(size_t _size)
return; return;
} }
deallocate(); deallocate();
sz = _size;
if(_size > fixed_size) if(_size > fixed_size)
{ {
ptr = new _Tp[_size]; ptr = new _Tp[_size];
sz = _size;
} }
} }
......
...@@ -27,6 +27,7 @@ TEST(CommandLineParser, testFailure) ...@@ -27,6 +27,7 @@ TEST(CommandLineParser, testFailure)
parser.get<bool>("h"); parser.get<bool>("h");
EXPECT_FALSE(parser.check()); EXPECT_FALSE(parser.check());
} }
TEST(CommandLineParser, testHas_noValues) TEST(CommandLineParser, testHas_noValues)
{ {
const char* argv[] = {"<bin>", "-h", "--info"}; const char* argv[] = {"<bin>", "-h", "--info"};
...@@ -218,4 +219,17 @@ TEST(CommandLineParser, positional_regression_5074_equal_sign) ...@@ -218,4 +219,17 @@ TEST(CommandLineParser, positional_regression_5074_equal_sign)
EXPECT_TRUE(parser.check()); 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 } // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment