Skip to content

Commit ae7b067

Browse files
Avoid overallocating for strings (#1099)
1 parent 33c1bfb commit ae7b067

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

source/string.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,8 @@ struct aws_string *aws_string_new_from_c_str(struct aws_allocator *allocator, co
189189
struct aws_string *aws_string_new_from_array(struct aws_allocator *allocator, const uint8_t *bytes, size_t len) {
190190
AWS_PRECONDITION(allocator);
191191
AWS_PRECONDITION(AWS_MEM_IS_READABLE(bytes, len));
192-
size_t malloc_size;
193-
if (aws_add_size_checked(sizeof(struct aws_string) + 1, len, &malloc_size)) {
194-
return NULL;
195-
}
196-
struct aws_string *str = aws_mem_acquire(allocator, malloc_size);
192+
193+
struct aws_string *str = aws_mem_acquire(allocator, offsetof(struct aws_string, bytes[len + 1]));
197194
if (!str) {
198195
return NULL;
199196
}

0 commit comments

Comments
 (0)