Skip to content

Commit

Permalink
Fix Bump::shrink illegal copies
Browse files Browse the repository at this point in the history
Fixes #230.
  • Loading branch information
overlookmotel committed Feb 14, 2024
1 parent f8278d6 commit 25c7d1f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,10 @@ impl Bump {
// Only reclaim the excess space (which requires a copy) if it
// is worth it: we are actually going to recover "enough" space
// and we can do a non-overlapping copy.
&& delta >= old_size / 2
// `(old_size + 1) / 2` so division rounds up rather than down,
// so this test fails for e.g. `old_size` = 1, `new_size` = 1
// or `old_size` = 5, `new_size` = 3 (which would overlap).
&& delta >= (old_size + 1) / 2
{
let footer = self.current_chunk_footer.get();
let footer = footer.as_ref();
Expand Down

0 comments on commit 25c7d1f

Please sign in to comment.