예제 #1
0
// the strings s1 and s2 need to be allocated
// check that s2 fits inside s1
char *strcat(char *s1, const char *s2) {
  int size1;
  int size2;

  size1 = __get_array_size(s1);
  size2 = __get_array_size(s2);
  INFER_EXCLUDE_CONDITION(size2>size1);
  return s1;
}
예제 #2
0
// s1 and s2 must be allocated
// n should not be greater than the size of s1 or s2
// return a non-deterministic integer
int memcmp(const void *s1, const void *s2, size_t n) {
  int size_s1;
  int size_s2;

  size_s1 = __get_array_size(s1);
  size_s2 = __get_array_size(s2);
  INFER_EXCLUDE_CONDITION((n>size_s1) || (n>size_s2));
  return __infer_nondet_int();
}
예제 #3
0
// the strings s1 and s2 need to be allocated
// check that n characters fit in s1 (because even if s2 is shorter than n, null characters are appended to s1)
char *strncpy(char *s1, const char *s2, size_t n) {
  int size1, size2;
  __infer_set_flag("ignore_return", ""); // no warnings if the return value is ignored

  size1 = __get_array_size(s1);
  size2 = __get_array_size(s2);
  INFER_EXCLUDE_CONDITION(n > size1);
  return s1;
}
예제 #4
0
// s1 and s2 must be allocated
// n should not be greater than the size of s1 or s2
// return s1
char *strncat(char *s1, const char *s2, size_t n) {
  int size_s1;
  int size_s2;

  size_s1 = __get_array_size(s1);
  size_s2 = __get_array_size(s2);
  INFER_EXCLUDE_CONDITION((n>size_s1) || (n>size_s2));
  return s1;
}
예제 #5
0
// s1 and s2 must be allocated.
// return a non-deterministic integer
int strcmp(const char *s1, const char *s2) {
  int size_s1;
  int size_s2;
  int res;
  res = __infer_nondet_int();

  size_s1 = __get_array_size(s1);
  size_s2 = __get_array_size(s2);
  return res;
}
예제 #6
0
// s1 and s2 must be allocated
// n must be between 0 and the minumum of the sizes of s1 and s2
void *memcpy(void *s1, const void *s2, size_t n) {
  int size_s1;
  int size_s2;
  __infer_set_flag("ignore_return", ""); // no warnings if the return value is ignored

  size_s1 = __get_array_size(s1);
  size_s2 = __get_array_size(s2);
  INFER_EXCLUDE_CONDITION((n < 0) || (n>size_s1) || (n>size_s2));
  return s1;
}
예제 #7
0
// s1 and s2 must be allocated.
// return an integer between 0 ans the size of s1
size_t strspn(const char *s1, const char *s2) {
  int size_s1;
  int size_s2;
  int res;
  res = __infer_nondet_int();

  size_s1 = __get_array_size(s1);
  size_s2 = __get_array_size(s2);
  INFER_EXCLUDE_CONDITION(res < 0 || res > size_s1);
  return res;
}
예제 #8
0
// s1 and s2 must be allocated
// n should not be greater than the size of s1 or s2
// return a non-deterministic integer
int strncmp(const char *s1, const char *s2, size_t n) {
  int size_s1;
  int size_s2;
  int res;
  res = __infer_nondet_int();

  size_s1 = __get_array_size(s1);
  size_s2 = __get_array_size(s2);
  INFER_EXCLUDE_CONDITION((n>size_s1) || (n>size_s2));
  return res;
}
예제 #9
0
파일: libc_basic.c 프로젝트: AlicWang/infer
// the strings s1 and s2 need to be allocated
// check that s2 fits inside s1
char* strcpy(char* s1, const char* s2) {
  int size1;
  int size2;
  __infer_set_flag("ignore_return",
                   ""); // no warnings if the return value is ignored
  __require_allocated_array(s1);
  size1 = __get_array_size(s1);
  __require_allocated_array(s2);
  size2 = __get_array_size(s2);
  INFER_EXCLUDE_CONDITION(size2 > size1);
  return s1;
}
예제 #10
0
// the strings s1 and s2 must be allocated
// nondeterministically return 0 or a pointer inside the string s1
char *strstr(const char *s1, const char *s2) {
  int size1, size2;
  int nondet;
  int offset;
  nondet = __infer_nondet_int();
  offset = __infer_nondet_int();

  size1 = __get_array_size(s1);
  size2 = __get_array_size(s2);
  if(nondet) return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >=size1);
  return (void *)s1 + offset;
}
예제 #11
0
// s needs to be allocated
// n should not be greater than the size of s
void *memset(void *s, int c, size_t n) {
  int size_s;
  __infer_set_flag("ignore_return", ""); // no warnings if the return value is ignored

  size_s = __get_array_size(s);
  INFER_EXCLUDE_CONDITION(n>size_s);
  return s;
}
예제 #12
0
// the string s must be allocated
// nondeterministically return 0 or a pointer inside the buffer
char *strchr(const char *s, int c) {
  int size;
  int nondet;
  int offset;
  nondet = __infer_nondet_int();
  offset = __infer_nondet_int();

  size = __get_array_size(s);
  if(nondet) return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >=size);
  return (void *)s + offset;
}
예제 #13
0
// the array s must be allocated
// n should not be greater than the size of s
// nondeterministically return 0 or a pointer within the first n elements of s
void *memchr(const void *s, int c, size_t n) {
  int size;
  int nondet;
  int offset;
  nondet = __infer_nondet_int();
  offset = __infer_nondet_int();

  size = __get_array_size(s);
  INFER_EXCLUDE_CONDITION(n > size);
  if(nondet) return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >= n);
  return (void *)s + offset;
}
예제 #14
0
// return NULL, or if s is NULL return a global variable, otherwise check that s has size at least L_tmpnam and return s
char *tmpnam(char *s) {
  int success;
  int size;

  success = __infer_nondet_int();
  if(!success) return NULL;
  if(s) {
    size = __get_array_size(s);
    INFER_EXCLUDE_CONDITION(size < L_tmpnam);
    return s;
  }
  else return _tmpnam_global;
}
예제 #15
0
// the string s must be allocated
// assign to endptr a pointer somewhere inside the string str
// result is nondeterministic
unsigned long strtoul(const char *str, char **endptr, int base) {
  int size;
  int offset;
  int res;
  size = __get_array_size(str);
  offset = __infer_nondet_int();
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >= size);
  if(endptr) *endptr = (char *) (str + offset);
  res = __infer_nondet_int();
  int errno_val = __infer_nondet_int();
  INFER_EXCLUDE_CONDITION(errno_val < 0);
  errno = errno_val;
  return res;
}
예제 #16
0
CFStringRef CFStringCreateWithBytesNoCopy (
                        CFAllocatorRef alloc,
                        const UInt8 *bytes,
                        CFIndex numBytes,
                        CFStringEncoding encoding,
                        Boolean isExternalRepresentation,
                        CFAllocatorRef contentsDeallocator ) {
   CFStringRef c;
   CFStringRef s =  __cf_alloc(c);
   if (s) {
     if (bytes) {
         __get_array_size(bytes);
         free(bytes);
     }
   }
   return s;
}
예제 #17
0
파일: libc_basic.c 프로젝트: AlicWang/infer
char* strchr(const char* s, int c) {
#else
const char* strchr(const char* s, int c) throw() { return strchr((char*)s, c); }

char* strchr(char* s, int c) throw() {
#endif
  int size;
  int nondet;
  int offset;
  nondet = __infer_nondet_int();
  offset = __infer_nondet_int();

  __require_allocated_array(s);
  size = __get_array_size(s);
  if (nondet)
    return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >= size);
  return (char*)s + offset;
}
예제 #18
0
파일: libc_basic.c 프로젝트: AlicWang/infer
char* strpbrk(const char* s1, const char* s2) {
#else
const char* strpbrk(const char* s1, const char* s2) throw() {
  return strpbrk((char*)s1, s2);
}

char* strpbrk(char* s1, const char* s2) throw() {
#endif
  int size1;
  int nondet;
  int offset;
  nondet = __infer_nondet_int();
  offset = __infer_nondet_int();
  __require_allocated_array(s1);
  size1 = __get_array_size(s1);
  __require_allocated_array(s2);
  if (nondet)
    return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >= size1);
  return (char*)s1 + offset;
}
예제 #19
0
파일: libc_basic.c 프로젝트: AlicWang/infer
void* memchr(const void* s, int c, size_t n) {
#else

const void* memchr(const void* s, int c, size_t n) throw() {
  return memchr((void*)s, c, n);
}

void* memchr(void* s, int c, size_t n) throw() {
#endif
  int size;
  int nondet;
  int offset;
  nondet = __infer_nondet_int();
  offset = __infer_nondet_int();
  __require_allocated_array(s);
  size = __get_array_size(s);
  INFER_EXCLUDE_CONDITION(n > size);
  if (nondet)
    return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >= n);
  return (char*)s + offset;
}
예제 #20
0
파일: libc_basic.c 프로젝트: AlicWang/infer
// the string s must be allocated
// return the size of the buffer - 1
size_t strlen(const char* s) {
  int size;
  __require_allocated_array(s);
  size = __get_array_size(s);
  return size - 1;
}
예제 #21
0
// the string s must be allocated
// return the size of the buffer - 1
size_t strlen(const char *s) {
  int size;
  size = __get_array_size(s);
  return size-1;
}
예제 #22
0
// the string s must be allocated; return the result of malloc with the same size
char *strdup(const char *s) {
  int size;
  size = __get_array_size(s);
  return malloc(size);
}
예제 #23
0
파일: libc_basic.c 프로젝트: AlicWang/infer
// the string s must be allocated; return the result of malloc with the same
// size
char* strdup(const char* s) {
  int size;
  __require_allocated_array(s);
  size = __get_array_size(s);
  return (char*)malloc(size);
}
예제 #24
0
// s must be allocated
// return s
char *strupr(char *s) {
  int size1;
  size1 = __get_array_size(s);
  return s;
}