Exemple #1
0
char* strchr(const char* s, int c) {
#else
// This overload is commented out on purpose.
// Standard headers define both functions with same __asm symbol which
// means they cannot be both defined. On the other hand, since both of them
// have same __asm symbol, mangling will be the same and infer will have
// specs for both functions (they both will have the same name)
// NOTE: this was tested on couple of systems, it may not be always true.
// 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_length(s);
  if (nondet)
    return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >= size);
  return (char*)s + offset;
}
Exemple #2
0
void FN_unreachable_statement_break_bad() {
  while (__infer_nondet_int()) {
    if (__infer_nondet_int()) {
      break;
      nop();
    }
  }
}
Exemple #3
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;
}
Exemple #4
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;
}
Exemple #5
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;
}
Exemple #6
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;
}
Exemple #7
0
void FP_loop_with_unreachable_good() {
  while (1) {
    if (__infer_nondet_int()) {
      infinite_loop_bad();
    }
  }
}
Exemple #8
0
void FP_loop_with_exit_good() {
  while (1) {
    if (__infer_nondet_int()) {
      exit(1);
    }
  }
}
Exemple #9
0
void FP_loop_with_return_good() {
  while (1) {
    if (__infer_nondet_int()) {
      return;
    }
  }
}
Exemple #10
0
void FP_loop_with_break_good() {
  while (1) {
    if (__infer_nondet_int()) {
      break;
    }
  }
}
Exemple #11
0
void FN_useless_else_bad() {
  if (__infer_nondet_int()) {
    exit(0);
  } else {
    nop();
  }
}
Exemple #12
0
 TLOR lO(const lo& o) {
   auto r = TLOR::S;
   if (__infer_nondet_int()) {
     r = TLOR::F;
   }
   return r;
 }
Exemple #13
0
// return a nondeterministic value between INT_MIN and INT_MAX
int atoi(const char *str) {
  int retu = INT_MAX;
  int retl = INT_MIN;
  int ret;
  if (__infer_nondet_int())  ret = retu;
  else ret = retl;
  return ret;
}
Exemple #14
0
// s1 and s2 must be allocated.
// return a non-deterministic integer
int strcmp(const char* s1, const char* s2) {
  int res;
  res = __infer_nondet_int();

  __require_allocated_array(s1);
  __require_allocated_array(s2);
  return res;
}
Exemple #15
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();
}
Exemple #16
0
static inline void gal(lt* t, ai a) {
  ASSERT(t);
  lo o = alo(a);
  if (__infer_nondet_int()) {
    al->tL(*t, o);
  } else {
    al->l(*t, o);
  }
}
Exemple #17
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;
  __require_allocated_array(s1);
  size_s1 = __get_array_length(s1);
  __require_allocated_array(s2);
  size_s2 = __get_array_length(s2);
  INFER_EXCLUDE_CONDITION((n > size_s1) || (n > size_s2));
  return __infer_nondet_int();
}
Exemple #18
0
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;
}
Exemple #19
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 res;
  res = __infer_nondet_int();
  __require_allocated_array(s1);
  size_s1 = __get_array_size(s1);
  __require_allocated_array(s2);
  INFER_EXCLUDE_CONDITION(res < 0 || res > size_s1);
  return res;
}
Exemple #20
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;
}
Exemple #21
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;
}
Exemple #22
0
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;
}
Exemple #23
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();
  __require_allocated_array(s1);
  size_s1 = __get_array_length(s1);
  __require_allocated_array(s2);
  size_s2 = __get_array_length(s2);
  INFER_EXCLUDE_CONDITION((n > size_s1) || (n > size_s2));
  return res;
}
Exemple #24
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;
}
Exemple #25
0
char* strstr(const char* s1, const char* s2) {
#else
// This overload is commented out on purpose. Look at strchr() for more info.
/*const char* strstr(const char* s1, const char* s2) throw() {
  return strstr((char*)s1, s2);
}*/

char* strstr(char* s1, const char* s2) throw() {
#endif
  int size1, size2;
  int nondet;
  int offset;
  nondet = __infer_nondet_int();
  offset = __infer_nondet_int();
  __require_allocated_array(s1);
  size1 = __get_array_length(s1);
  __require_allocated_array(s2);
  if (nondet)
    return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >= size1);
  return (char*)s1 + offset;
}
Exemple #26
0
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;
}
Exemple #27
0
void* memchr(const void* s, int c, size_t n) {
#else
// This overload is commented out on purpose. Look at strchr() for more info.
// 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_length(s);
  INFER_EXCLUDE_CONDITION(n > size);
  if (nondet)
    return 0;
  INFER_EXCLUDE_CONDITION(offset < 0 || offset >= n);
  return (char*)s + offset;
}
Exemple #28
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) {
    __require_allocated_array(s);
    size = __get_array_length(s);
    INFER_EXCLUDE_CONDITION(size < L_tmpnam);
    return s;
  } else
    return _tmpnam_global;
}
Exemple #29
0
wint_t CLIBCALL fgetwc(FILE *stream)
{
  return __infer_nondet_int();
}
Exemple #30
0
    return NULL;
  if (s) {
    __require_allocated_array(s);
    size = __get_array_size(s);
    INFER_EXCLUDE_CONDITION(size < L_tmpnam);
    return s;
  } else
    return _tmpnam_global;
}

// nondeterministically return NULL or the original stream
FILE* freopen(const char* __restrict filename,
              const char* __restrict mode,
              FILE* __restrict stream) {
  int n;
  n = __infer_nondet_int();
  if (n)
    return NULL;
  else
    return stream;
}

// modeled using free, can return EOF
int fclose(FILE* stream) {
  int n;
  free(stream);
  n = __infer_nondet_int();
  if (n > 0)
    return 0;
  else
    return EOF;