Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_allocator: Check for room to split the first block
Changing the check in Block::AllocLast(). Usually, during an allocation, a free block is checked for enough space for the allocation. If there more than enough space, but not enough to hold another block, the excess is appended to the previous Block. This is not possible with the first Block since there isn't a previous Block. In the case of the first Block, the extra space will become part of the block and the Block will be returned to the caller. Before this change, even when there was not enough room for the first Block to be split into two, it was. This caused heap corruption and eventually a crash. As part of this fix, the unit tests were made less brittle and more exhaustive by adding test utilities that manage aligned and unaligned buffers, and then ensuring unit test coverage of every path though AllocFirst, CanAllocLast, and AllocLast. Bug: 366175024 Change-Id: Ic3c9538e5e33eaf507f08f0d3ac54361b5dcf998 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/235312 Pigweed-Auto-Submit: Aaron Green <[email protected]> Reviewed-by: John Comito <[email protected]> Reviewed-by: Ewout van Bekkum <[email protected]> Lint: Lint 🤖 <[email protected]> Reviewed-by: Keir Mierle <[email protected]> Commit-Queue: Auto-Submit <[email protected]> Docs-Not-Needed: Aaron Green <[email protected]> Presubmit-Verified: CQ Bot Account <[email protected]>
- Loading branch information