Debian Codegraph @

crt/aws-c-common/verification/cbmc/stubs/aws_array_list_swap_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 /**
7 * FUNCTION: aws_array_list_swap
8 *
9 * We override aws_array_list_swap because mem_swap makes CBMC
10 * struggle (because of the many memcpys) and because the
11 * array_list_get_at in before the mem_swap are unneccessary if we
12 * stub out mem_swap. Instead we add a havoc assumption on the two
13 * swapped byted to ensure that no assertion on the values of the two
14 * cells is made afterwards.
15 */
16
17 #include <aws/common/array_list.h>
18 #include <proof_helpers/nondet.h>
19
20 void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, size_t b) {
21 assert(a < list->length);
22 assert(b < list->length);
23 assert(aws_array_list_is_valid(list));
24
25 if (a == b) {
26 AWS_POSTCONDITION(aws_array_list_is_valid(list));
27 return;
28 }
29
30 /* Havoc one byte of each item so that assertions on their value
31 * fail */
32 if (list->item_size > 0) {
33 size_t item_sz = list->item_size;
34 size_t offset_a;
35 __CPROVER_assume(offset_a < item_sz);
36 ((uint8_t *)list->data)[(a * item_sz) + offset_a] = nondet_uint8_t();
37
38 size_t offset_b;
39 __CPROVER_assume(offset_b < item_sz);
40 ((uint8_t *)list->data)[(b * item_sz) + offset_b] = nondet_uint8_t();
41 }
42
43 return;
44 }