Skip to content

Commit 5a22e0d

Browse files
authored
Merge pull request #1222 from evoskuil/version3
Fix build_chunk and its extra reserve test case.
2 parents fa39f39 + b5892f1 commit 5a22e0d

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

include/bitcoin/system/impl/utility/data.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ inline data_chunk build_chunk(const loaf& slices, size_t extra_reserve)
7676
for (const auto& slice: slices)
7777
out.insert(out.end(), slice.begin(), slice.end());
7878

79-
// Pad any unfilled remainder of the array with zeros.
80-
std::fill(&out[size], &out[reserved], 0x00);
79+
// Pad any unfilled remainder of the vector with zeros.
80+
out.insert(out.end(), reserved - size, 0x00);
8181
return out;
8282
}
8383

test/utility/data.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,23 @@ BOOST_AUTO_TEST_CASE(data__build_chunk__three_arrays__expected_size_and_value)
170170

171171
// build_chunk(,)
172172

173-
BOOST_AUTO_TEST_CASE(data__build_chunk__extra_reserve__expected_size_and_capacity)
173+
BOOST_AUTO_TEST_CASE(data__build_chunk__extra_reserve__expected_size_zeroed)
174174
{
175175
const auto result = build_chunk(
176176
{
177-
byte_array<2>{ { 0, 0 } },
177+
byte_array<2>{ { 1, 1 } },
178178
byte_array<1>{ { 42 } },
179-
byte_array<3>{ { 0, 0, 0 } }
180-
}, 42);
181-
BOOST_REQUIRE_EQUAL(result.size(), 2u + 1u + 3u);
179+
byte_array<3>{ { 1, 1, 1 } }
180+
}, 2);
181+
BOOST_REQUIRE_EQUAL(result[0], 1u);
182+
BOOST_REQUIRE_EQUAL(result[1], 1u);
182183
BOOST_REQUIRE_EQUAL(result[2], 42u);
183-
BOOST_REQUIRE_EQUAL(result.capacity(), 2u + 1u + 3u + 42u);
184+
BOOST_REQUIRE_EQUAL(result[3], 1u);
185+
BOOST_REQUIRE_EQUAL(result[4], 1u);
186+
BOOST_REQUIRE_EQUAL(result[5], 1u);
187+
BOOST_REQUIRE_EQUAL(result[6], 0u);
188+
BOOST_REQUIRE_EQUAL(result[7], 0u);
189+
BOOST_REQUIRE_EQUAL(result.size(), 2u + 1u + 3u + 2u);
184190
}
185191

186192
// extend_data

0 commit comments

Comments
 (0)