Debian Codegraph @

crt/aws-c-common/verification/cbmc/stubs/s_emplace_item_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 /**
13 * Attempts to locate an element at key. If no such element was found,
14 * creates a new element, with value initialized to NULL. In either case, a
15 * pointer to the element is placed in *p_elem.
16 *
17 * If was_created is non-NULL, *was_created is set to 0 if an existing
18 * element was found, or 1 is a new element was created.
19 *
20 * Returns AWS_OP_SUCCESS if an item was found or created.
21 * Raises AWS_ERROR_OOM if hash table expansion was required and memory
22 * allocation failed.
23 */
24
25 struct hash_table_entry *__CPROVER_file_local_hash_table_c_s_emplace_item(
26 struct hash_table_state *state,
27 struct hash_table_entry entry,
28 size_t probe_idx) {
29 AWS_PRECONDITION(hash_table_state_is_valid(state), "Input hash_table_state [state] must be valid.");
30
31 if (entry.hash_code == 0) {
32 AWS_POSTCONDITION(hash_table_state_is_valid(state), "Output hash_table_state [state] must be valid.");
33 return NULL;
34 }
35
36 size_t index;
37 __CPROVER_assume(index < state->size);
38 __CPROVER_assume(state->slots[index].hash_code == 0);
39 state->slots[index] = entry;
40 size_t empty_slot_idx;
41 __CPROVER_assume(hash_table_state_has_an_empty_slot(state, &empty_slot_idx));
42 AWS_POSTCONDITION(hash_table_state_is_valid(state), "Output hash_table_state [state] must be valid.");
43 return &state->slots[index];
44 }