| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#undef memcpy |
| 7 |
|
| 8 |
#include <proof_helpers/nondet.h> |
| 9 |
#include <stdint.h> |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
void *memcpy_impl(void *dst, const void *src, size_t n) { |
| 18 |
__CPROVER_precondition( |
| 19 |
__CPROVER_POINTER_OBJECT(dst) != __CPROVER_POINTER_OBJECT(src) || |
| 20 |
((const char *)src >= (const char *)dst + n) || ((const char *)dst >= (const char *)src + n), |
| 21 |
"memcpy src/dst overlap"); |
| 22 |
__CPROVER_precondition(src != NULL && __CPROVER_r_ok(src, n), "memcpy source region readable"); |
| 23 |
__CPROVER_precondition(dst != NULL && __CPROVER_w_ok(dst, n), "memcpy destination region writeable"); |
| 24 |
|
| 25 |
if (n > 0) { |
| 26 |
size_t index; |
| 27 |
__CPROVER_assume(index < n); |
| 28 |
((uint8_t *)dst)[index] = nondet_uint8_t(); |
| 29 |
} |
| 30 |
return dst; |
| 31 |
} |
| 32 |
|
| 33 |
void *memcpy(void *dst, const void *src, size_t n) { |
| 34 |
return memcpy_impl(dst, src, n); |
| 35 |
} |
| 36 |
|
| 37 |
void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __CPROVER_size_t size) { |
| 38 |
(void)size; |
| 39 |
return memcpy_impl(dst, src, n); |
| 40 |
} |