Skip to content

Commit

Permalink
Avoid overallocating for strings (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin authored Apr 2, 2024
1 parent 33c1bfb commit ae7b067
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions source/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,8 @@ struct aws_string *aws_string_new_from_c_str(struct aws_allocator *allocator, co
struct aws_string *aws_string_new_from_array(struct aws_allocator *allocator, const uint8_t *bytes, size_t len) {
AWS_PRECONDITION(allocator);
AWS_PRECONDITION(AWS_MEM_IS_READABLE(bytes, len));
size_t malloc_size;
if (aws_add_size_checked(sizeof(struct aws_string) + 1, len, &malloc_size)) {
return NULL;
}
struct aws_string *str = aws_mem_acquire(allocator, malloc_size);

struct aws_string *str = aws_mem_acquire(allocator, offsetof(struct aws_string, bytes[len + 1]));
if (!str) {
return NULL;
}
Expand Down

0 comments on commit ae7b067

Please sign in to comment.