Debian Codegraph @

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

raw symbols SCIP
1 #include <aws/common/hash_table.h>
2 #include <aws/common/math.h>
3 #include <aws/common/private/hash_table_impl.h>
4 #include <aws/common/string.h>
5
6 #include <limits.h>
7 #include <proof_helpers/make_common_data_structures.h>
8 #include <proof_helpers/utils.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 int __CPROVER_file_local_hash_table_c_s_update_template_size(
13 struct hash_table_state *template,
14 size_t expected_elements);
15
16 int __CPROVER_file_local_hash_table_c_s_expand_table(struct aws_hash_table *map) {
17 struct hash_table_state *old_state = map->p_impl;
18 struct hash_table_state template = *old_state;
19
20 if (__CPROVER_file_local_hash_table_c_s_update_template_size(&template, template.size * 2) != AWS_OP_SUCCESS) {
21 return AWS_OP_ERR;
22 }
23
24 /* Don't use s_alloc_state because that will call calloc and we want non-det values for the entries */
25 size_t required_bytes = sizeof(struct hash_table_state) + template.size * sizeof(struct hash_table_entry);
26
27 /* An empty slot has hashcode 0. So this marks all slots as empty */
28 struct hash_table_state *new_state = aws_mem_acquire(template.alloc, required_bytes);
29
30 if (new_state == NULL) {
31 return AWS_OP_ERR;
32 }
33 struct hash_table_state *d1 = new_state;
34 *new_state = template;
35
36 map->p_impl = new_state;
37 void *d2 = map;
38 void *d3 = map->p_impl;
39
40 aws_mem_release(new_state->alloc, old_state);
41 __CPROVER_assume(aws_hash_table_is_valid(map));
42 size_t empty_slot_idx;
43 __CPROVER_assume(aws_hash_table_has_an_empty_slot(map, &empty_slot_idx));
44 return AWS_OP_SUCCESS;
45 }