Debian Codegraph @

crt/s2n/tests/cbmc/stubs/memset_havoc.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. A copy of the License is
6 * located at
7 *
8 * http://aws.amazon.com/apache2.0/
9 *
10 * or in the "license" file accompanying this file. This file is distributed on an
11 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 * implied. See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #undef memset
17
18 #include <cbmc_proof/nondet.h>
19 #include <stddef.h>
20
21 /**
22 * Override the version of memset used by CBMC. Users may not want to pay
23 * for the cost of performing the computation of memset in proofs. In that
24 * case, this stub at least checks for the preconditions and make sure to
25 * havoc all elements pointed by *s up to n.
26 */
27 void *memset_impl(void *s, int c, size_t n) {
28 __CPROVER_precondition(__CPROVER_w_ok(s, n), "memset destination region writeable");
29 if (n > 0) {
30 size_t idx;
31 __CPROVER_assume(idx < n);
32 ((uint8_t *)s)[idx] = nondet_uint8_t();
33 }
34 return s;
35 }
36
37 void *memset(void *s, int c, size_t n) {
38 return memset_impl(s, c, n);
39 }
40
41 void *__builtin___memset_chk(void *s, int c, size_t n, size_t os) {
42 (void)os;
43 return memset_impl(s, c, n);
44 }