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:
1 file changed
+1
-1
@@ -155,7 +155,7 @@ class PoolResource final
|
|||||||
void AllocateChunk()
|
void AllocateChunk()
|
||||||
{
|
{
|
||||||
// if there is still any available memory left, put it into the freelist.
|
// 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) {
|
if (0 != remaining_available_bytes) {
|
||||||
ASAN_UNPOISON_MEMORY_REGION(m_available_memory_it, sizeof(ListNode));
|
ASAN_UNPOISON_MEMORY_REGION(m_available_memory_it, sizeof(ListNode));
|
||||||
PlacementAddToList(m_available_memory_it, m_free_lists[remaining_available_bytes / ELEM_ALIGN_BYTES]);
|
PlacementAddToList(m_available_memory_it, m_free_lists[remaining_available_bytes / ELEM_ALIGN_BYTES]);
|
||||||
|
|||||||
Reference in new issue
Block a user