mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-03 13:53:02 +01:00
coins: replace std::distance with unambiguous pointer subtraction
Avoid calling `std::distance` on null pointers in `PoolResource::AllocateChunk`.
Compute remaining bytes with `m_available_memory_end - m_available_memory_it` instead, which is well-defined to be `0` when both are `nullptr`.
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
This commit is contained in:
@@ -155,7 +155,7 @@ class PoolResource final
|
||||
void AllocateChunk()
|
||||
{
|
||||
// if there is still any available memory left, put it into the freelist.
|
||||
size_t remaining_available_bytes = std::distance(m_available_memory_it, m_available_memory_end);
|
||||
size_t remaining_available_bytes = m_available_memory_end - m_available_memory_it;
|
||||
if (0 != remaining_available_bytes) {
|
||||
ASAN_UNPOISON_MEMORY_REGION(m_available_memory_it, sizeof(ListNode));
|
||||
PlacementAddToList(m_available_memory_it, m_free_lists[remaining_available_bytes / ELEM_ALIGN_BYTES]);
|
||||
|
||||
Reference in New Issue
Block a user