Skip to content

Commit

Permalink
lone/value/bytes: copy uninitialized memory
Browse files Browse the repository at this point in the history
The general memory allocation functions now return zeroed memory blocks.
Avoid duplicate work by not zeroing the memory a second time
or at all when copying an external buffer.
  • Loading branch information
matheusmoreira committed Dec 13, 2023
1 parent b569393 commit f264ea2
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions source/lone/value/bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct lone_value lone_bytes_transfer_bytes(struct lone_lisp *lone, struct lone_

struct lone_value lone_bytes_copy(struct lone_lisp *lone, unsigned char *pointer, size_t count)
{
unsigned char *copy = lone_allocate(lone, count + 1);
unsigned char *copy = lone_allocate_uninitialized(lone, count + 1);
lone_memory_move(pointer, copy, count);
copy[count] = '\0';
return lone_bytes_transfer(lone, copy, count, true);
Expand All @@ -32,6 +32,5 @@ struct lone_value lone_bytes_copy(struct lone_lisp *lone, unsigned char *pointer
struct lone_value lone_bytes_create(struct lone_lisp *lone, size_t count)
{
unsigned char *pointer = lone_allocate(lone, count + 1);
lone_memory_zero(pointer, count + 1);
return lone_bytes_transfer(lone, pointer, count, true);
}

0 comments on commit f264ea2

Please sign in to comment.