Debian Codegraph @

crt/aws-c-common/verification/cbmc/stubs/memmove_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 #undef memmove
7
8 #include <proof_helpers/nondet.h>
9 #include <stdint.h>
10
11 /**
12 * Override the version of memmove used by CBMC.
13 * Source: public domain code copied from https://clc-wiki.net/wiki/memmove
14 */
15 void *memmove_impl(void *dest, const void *src, size_t n) {
16 if (n > 0) {
17 (void)*(char *)dest; /* check that the memory is accessible */
18 (void)*(const char *)src; /* check that the memory is accessible */
19 (void)*(((unsigned char *)dest) + n - 1); /* check that the memory is accessible */
20 (void)*(((const unsigned char *)src) + n - 1); /* check that the memory is accessible */
21
22 unsigned char *pd = dest;
23 const unsigned char *ps = src;
24 if ((ps) < (pd)) {
25 for (pd += n, ps += n; n--;)
26 *--pd = *--ps;
27 } else {
28 while (n) {
29 *pd++ = *ps++;
30 n--;
31 }
32 }
33 }
34 return dest;
35 }
36
37 void *memmove(void *dest, const void *src, size_t n) {
38 return memmove_impl(dest, src, n);
39 }
40
41 void *__builtin___memmove_chk(void *dest, const void *src, size_t n, size_t size) {
42 (void)size;
43 return memmove_impl(dest, src, n);
44 }