Skip to content

Commit

Permalink
Backfill to logical on set() head expand.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jan 7, 2025
1 parent 5f140df commit ecb35cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/memory/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ memory_ptr map::set(size_t offset, size_t size, uint8_t backfill) NOEXCEPT

// Fill new capacity as offset may not be at end due to expansion.
BC_PUSH_WARNING(NO_POINTER_ARITHMETIC)
std::fill_n(memory_map_ + old_capacity, new_capacity - old_capacity,
std::fill_n(memory_map_ + logical_, new_capacity - logical_,
backfill);
BC_POP_WARNING()
}
Expand Down
9 changes: 4 additions & 5 deletions test/memory/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,10 @@ BOOST_AUTO_TEST_CASE(map__set__loaded__expected_fill)
BOOST_REQUIRE_EQUAL(data[ 5], 'a'); // offset + 0
BOOST_REQUIRE_EQUAL(data[ 6], 'b'); // offset + 1
BOOST_REQUIRE_EQUAL(data[ 7], 'c'); // offset + 2
BOOST_REQUIRE_EQUAL(data[ 8], fill1); // expansion
BOOST_REQUIRE_EQUAL(data[ 9], fill1); // expansion
BOOST_REQUIRE_EQUAL(data[10], fill1); // expansion
BOOST_REQUIRE_EQUAL(data[11], fill1); // sub1(offset + size + to_half(offset + size))

BOOST_REQUIRE_EQUAL(data[ 8], fill2); // expansion, macos trims on remap here.
BOOST_REQUIRE_EQUAL(data[ 9], fill2); // expansion, so it goes to zero if not refilled.
BOOST_REQUIRE_EQUAL(data[10], fill2); // expansion
BOOST_REQUIRE_EQUAL(data[11], fill2); // sub1(offset + size + to_half(offset + size))
BOOST_REQUIRE_EQUAL(data[12], fill2); // cannot assume mmap default fill
BOOST_REQUIRE_EQUAL(data[13], fill2); // cannot assume mmap default fill
BOOST_REQUIRE_EQUAL(data[14], fill2); // cannot assume mmap default fill
Expand Down

0 comments on commit ecb35cc

Please sign in to comment.