Esempio n. 1
0
File: string.c Progetto: danpoe/cbmc
void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __CPROVER_size_t size)
{
  __CPROVER_HIDE:
  #ifdef __CPROVER_STRING_ABSTRACTION
  __CPROVER_assert(__CPROVER_buffer_size(src)>=n, "memcpy buffer overflow");
  __CPROVER_assert(__CPROVER_buffer_size(dst)>=n, "memcpy buffer overflow");
  __CPROVER_assert(__CPROVER_buffer_size(dst)==s, "builtin object size");
  //  for(size_t i=0; i<n ; i++) dst[i]=src[i];
  if(__CPROVER_is_zero_string(src) &&
     n > __CPROVER_zero_string_length(src))
  {
    __CPROVER_is_zero_string(dst)=1;
    __CPROVER_zero_string_length(dst)=__CPROVER_zero_string_length(src);
  }
  else if(!(__CPROVER_is_zero_string(dst) &&
            n <= __CPROVER_zero_string_length(dst)))
    __CPROVER_is_zero_string(dst)=0;
  #else
  __CPROVER_assert(__CPROVER_POINTER_OBJECT(dst)!=
                   __CPROVER_POINTER_OBJECT(src), "memcpy src/dst overlap");
  (void)size;
  //for(__CPROVER_size_t i=0; i<n ; i++) ((char *)dst)[i]=((const char *)src)[i];
  char src_n[n];
  __CPROVER_array_copy(src_n, (char*)src);
  __CPROVER_array_replace((char*)dst, src_n);
  #endif
  return dst;
}
Esempio n. 2
0
inline void *realloc(void *ptr, __CPROVER_size_t malloc_size)
{
  __CPROVER_HIDE:;

  // if ptr is NULL, this behaves like malloc
  if(ptr==0)
    return malloc(malloc_size);

  // if malloc-size is 0, allocate new minimum sized object
  // and free original
  if(malloc_size==0)
  {
    free(ptr);
    return malloc(1);
  }

  __CPROVER_assert(__CPROVER_DYNAMIC_OBJECT(ptr),
                   "realloc argument is dynamic object");

  // this shouldn't move if the new size isn't bigger
  res=malloc(malloc_size);
  __CPROVER_array_copy(res, ptr);
  free(ptr);

  return res;
}
Esempio n. 3
0
void testB()
{
  char arrayB1[100], arrayB2[100];

  arrayB2[10]=11;
  __CPROVER_array_copy(arrayB1, arrayB2);

  __CPROVER_assert(arrayB1[10]==11, "arrayB1[10] is OK");
}
Esempio n. 4
0
File: string.c Progetto: danpoe/cbmc
void *memmove(void *dest, const void *src, size_t n)
{
  __CPROVER_HIDE:;
  #ifdef __CPROVER_STRING_ABSTRACTION
  __CPROVER_assert(__CPROVER_buffer_size(src)>=n, "memmove buffer overflow");
  // dst = src (with overlap allowed)
  if(__CPROVER_is_zero_string(src) &&
     n > __CPROVER_zero_string_length(src))
  {
    __CPROVER_is_zero_string(src)=1;
    __CPROVER_zero_string_length(dest)=__CPROVER_zero_string_length(src);
  }
  else
    __CPROVER_is_zero_string(dest)=0;
  #else
  char src_n[n];
  __CPROVER_array_copy(src_n, (char*)src);
  __CPROVER_array_replace((char*)dest, src_n);
  #endif
  return dest;
}