Skip to content

Commit

Permalink
lone/memory: calculate copy size with min function
Browse files Browse the repository at this point in the history
Less complex, more readable, better expresses the intent.
  • Loading branch information
matheusmoreira committed Dec 13, 2023
1 parent 443d090 commit cd44349
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/lone/memory/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <lone/linux.h>
#include <lone/memory/allocator.h>
#include <lone/memory/functions.h>
#include <lone/utilities.h>

static size_t __attribute__((const)) lone_next_power_of_2(size_t n)
{
Expand Down Expand Up @@ -85,7 +86,7 @@ void * lone_reallocate(struct lone_lisp *lone, void *pointer, size_t size)
*new = ((struct lone_memory *) lone_allocate(lone, size)) - 1;

if (pointer) {
lone_memory_move(old->pointer, new->pointer, new->size < old->size ? new->size : old->size);
lone_memory_move(old->pointer, new->pointer, lone_min(old->size, new->size));
lone_deallocate(lone, pointer);
}

Expand Down

0 comments on commit cd44349

Please sign in to comment.