fix: change payload size when realloc

This commit is contained in:
Renge 2022-03-25 23:45:01 -04:00
parent c227704733
commit 507276d82f
2 changed files with 4 additions and 4 deletions

View File

@ -4,13 +4,10 @@
int main(int argc, char const *argv[]) { int main(int argc, char const *argv[]) {
sf_set_magic(0x0); sf_set_magic(0x0);
size_t sz_x = sizeof(double) * 8, sz_y = sizeof(int); size_t sz_x = sizeof(int) * 20, sz_y = sizeof(int) * 16;
void *x = sf_malloc(sz_x); void *x = sf_malloc(sz_x);
sf_realloc(x, sz_y); sf_realloc(x, sz_y);
// cr_assert_not_null(x, "x is NULL!");
// sf_block *bp = (sf_block *)((char *)x - 16);
sf_show_heap(); sf_show_heap();

View File

@ -180,7 +180,10 @@ void *sf_realloc(void *pp, sf_size_t rsize)
else else
{ {
if (size - new_size < min) if (size - new_size < min)
{
set_entire_header(block, rsize, size, 1, get_prv_alloc(block->header), 0);
return block->body.payload; return block->body.payload;
}
else else
{ {
sf_block *ptr = split_block(block, new_size); sf_block *ptr = split_block(block, new_size);