Debian Codegraph @

crt/aws-c-common/verification/cbmc/stubs/s_remove_node_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: s_remove_node
8 *
9 * This function overrides the original implementation of the
10 * s_remove_node function from priority_queue.h with a no_op.
11 *
12 * It is safe to use as long as there are no assertions on the
13 * positions of elements in the priority queue after its invocation,
14 * as it doesn't really remove an element and reorders the rest, but
15 * it just reduces the length of both of the array lists of the
16 * priority queue by 1.
17 */
18
19 #include <aws/common/priority_queue.h>
20
21 int __CPROVER_file_local_priority_queue_c_s_remove_node(
22 struct aws_priority_queue *queue,
23 void *item,
24 size_t item_index) {
25 assert(aws_priority_queue_is_valid(queue));
26 assert(item && AWS_MEM_IS_WRITABLE(item, queue->container.item_size));
27
28 /* If aws_array_list_get_at succeeds, it means that the item_index
29 * is in range of the container, and thus the queue has at least
30 * item_index + 1 elements */
31 if (aws_array_list_get_at(&queue->container, item, item_index)) {
32 /* shouldn't happen, but if it does we've already raised an error... */
33 assert(aws_priority_queue_is_valid(queue));
34 return AWS_OP_ERR;
35 }
36
37 /* This can never underflow, as aws_array_list_get_at has
38 * succeeded, which means that the container has at least one
39 * item. Also if the backpointers array_list is initialized, it is
40 * constrained to have the same length as the container array_list
41 * (as queue is a valid priority queue) and thus is guaranteed to
42 * not underflow. */
43 queue->container.length -= 1;
44 if (queue->backpointers.data) {
45 queue->backpointers.length -= 1;
46 }
47
48 assert(aws_priority_queue_is_valid(queue));
49 return AWS_OP_SUCCESS;
50 }