Debian Codegraph @

crt/aws-c-common/verification/cbmc/stubs/aws_string_new_from_array_override.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/common/string.h>
7 #include <proof_helpers/nondet.h>
8
9 /**
10 * Override the aws_string_new_from_array to just give non-det bytes, rather than doing the memcpy.
11 * Since we already check AWS_MEM_IS_READABLE(bytes, len) in the precondition, this is sound - it overapproximates
12 * the behaviour of the real function, and has all the same memory safety checks.
13 */
14 struct aws_string *aws_string_new_from_array(struct aws_allocator *allocator, const uint8_t *bytes, size_t len) {
15 AWS_PRECONDITION(allocator);
16 AWS_PRECONDITION(AWS_MEM_IS_READABLE(bytes, len));
17
18 size_t malloc_size = sizeof(struct aws_string) + 1 + len;
19
20 struct aws_string *str = malloc(malloc_size);
21
22 if (str == NULL) {
23 return NULL;
24 }
25
26 __CPROVER_assume(str->allocator == allocator);
27 __CPROVER_assume(str->len == len);
28 __CPROVER_assume(str->bytes[len] == '\0');
29 AWS_RETURN_WITH_POSTCONDITION(str, aws_string_is_valid(str));
30 }