Skip to content

Commit af73aec

Browse files
committed
added memcpy_chk implementation
1 parent 8c7d1e3 commit af73aec

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/ansi-c/library/string.c

+33
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,39 @@ inline void *memmove(void *dest, const void *src, size_t n)
674674
return dest;
675675
}
676676

677+
/* FUNCTION: __builtin___memmove_chk */
678+
679+
#ifndef __CPROVER_STRING_H_INCLUDED
680+
#include <string.h>
681+
#define __CPROVER_STRING_H_INCLUDED
682+
#endif
683+
684+
#undef memmove
685+
686+
inline void *__builtin___memmove_chk(void *dest, const void *src, size_t n, __CPROVER_size_t size)
687+
{
688+
__CPROVER_HIDE:;
689+
#ifdef __CPROVER_STRING_ABSTRACTION
690+
__CPROVER_assert(__CPROVER_buffer_size(src)>=n, "memmove buffer overflow");
691+
__CPROVER_assert(__CPROVER_buffer_size(dest)==size, "builtin object size");
692+
// dst = src (with overlap allowed)
693+
if(__CPROVER_is_zero_string(src) &&
694+
n > __CPROVER_zero_string_length(src))
695+
{
696+
__CPROVER_is_zero_string(src)=1;
697+
__CPROVER_zero_string_length(dest)=__CPROVER_zero_string_length(src);
698+
}
699+
else
700+
__CPROVER_is_zero_string(dest)=0;
701+
#else
702+
(void)size;
703+
char src_n[n];
704+
__CPROVER_array_copy(src_n, (char*)src);
705+
__CPROVER_array_replace((char*)dest, src_n);
706+
#endif
707+
return dest;
708+
}
709+
677710
/* FUNCTION: memcmp */
678711

679712
#ifndef __CPROVER_STRING_H_INCLUDED

0 commit comments

Comments
 (0)