From ae7b067d9274d2d3faa1d3ae42d489a6986661f7 Mon Sep 17 00:00:00 2001 From: Dmitriy Musatkin <63878209+DmitriyMusatkin@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:36:01 -0700 Subject: [PATCH] Avoid overallocating for strings (#1099) --- source/string.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/source/string.c b/source/string.c index a3d2c204e..2fd791230 100644 --- a/source/string.c +++ b/source/string.c @@ -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; }