Skip to content

Commit

Permalink
Make heap small chunk size setting logic more precise/correct
Browse files Browse the repository at this point in the history
Prior to this commit, the heap small chunk size setting logic would
bitwise-or in the size into the appropriate bits of the small chunk
but this is technically incorrect as it doesn't clear out the bits
first.

This commit changes the logic to ensure the relevant bits are cleared
first before the new size is bitwise-or'd in.
  • Loading branch information
dipinhora committed Oct 9, 2024
1 parent 2ef3e4b commit 8ebdedb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libponyrt/mem/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static void set_small_chunk_size(small_chunk_t* chunk, size_t size)

// left shift size to get bits in the right spot for OR'ing into `chunk->m`
size = size << SMALL_CHUNK_SIZECLASS_SHIFT;
((chunk_t*)chunk)->m = (char*)((uintptr_t)((chunk_t*)chunk)->m | (size & SMALL_CHUNK_SIZECLASS_BITMASK));
((chunk_t*)chunk)->m = (char*)(((uintptr_t)((chunk_t*)chunk)->m & ~SMALL_CHUNK_SIZECLASS_BITMASK) | (size & SMALL_CHUNK_SIZECLASS_BITMASK));
}

static bool get_chunk_needs_clearing(chunk_t* chunk)
Expand Down

0 comments on commit 8ebdedb

Please sign in to comment.