fix: wrong rsize in realloc
This commit is contained in:
parent
2b554b4c5c
commit
c227704733
|
@ -4,15 +4,15 @@
|
|||
int main(int argc, char const *argv[]) {
|
||||
sf_set_magic(0x0);
|
||||
|
||||
size_t sz_x = sizeof(int), sz_y = 10, sz_x1 = sizeof(int) * 20;
|
||||
size_t sz_x = sizeof(double) * 8, sz_y = sizeof(int);
|
||||
void *x = sf_malloc(sz_x);
|
||||
/* void *y = */ sf_malloc(sz_y);
|
||||
x = sf_realloc(x, sz_x1);
|
||||
sf_realloc(x, sz_y);
|
||||
|
||||
// cr_assert_not_null(x, "x is NULL!");
|
||||
// sf_block *bp = (sf_block *)((char *)x - 16);
|
||||
|
||||
|
||||
|
||||
sf_show_heap();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -167,7 +167,7 @@ void *sf_realloc(void *pp, sf_size_t rsize)
|
|||
sf_block *block = (sf_block *)(((intptr_t)pp) - 2 * sizeof(sf_header));
|
||||
valid_pointer(block);
|
||||
sf_size_t size = get_block_size(block->header);
|
||||
sf_size_t new_size = get_min_size(size);
|
||||
sf_size_t new_size = get_min_size(rsize);
|
||||
if (new_size >= size)
|
||||
{
|
||||
sf_block *new = (sf_block *)(((intptr_t)sf_malloc(rsize)) - 2 * sizeof(sf_header));
|
||||
|
@ -184,7 +184,9 @@ void *sf_realloc(void *pp, sf_size_t rsize)
|
|||
else
|
||||
{
|
||||
sf_block *ptr = split_block(block, new_size);
|
||||
put_block(ptr);
|
||||
set_entire_header(block, rsize, new_size, 1, get_prv_alloc(block->header), 0);
|
||||
set_entire_header(ptr, 0, get_block_size(ptr->header), 0, get_prv_alloc(ptr->header), 0);
|
||||
release_block(ptr);
|
||||
return block->body.payload;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user