コード例 #1
0
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: CFString.c プロジェクト: Dharin-shah/infer
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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// 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
ファイル: libc_basic.c プロジェクト: Rooneyrui/infer
// s must be allocated
// return s
char *strupr(char *s) {
  int size1;
  size1 = __get_array_size(s);
  return s;
}