Esempio n. 1
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;
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
0
void* infer__builtin___memset_chk(void* dest,
                                  int val,
                                  unsigned long len,
                                  unsigned long dstlen) {
  INFER_EXCLUDE_CONDITION(dstlen < len);
  return dest;
}
Esempio n. 5
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;
}
Esempio n. 6
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;
}
Esempio n. 7
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();
}
Esempio n. 8
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;
}
Esempio n. 9
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;
}
Esempio n. 10
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();
}
Esempio n. 11
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;
  __infer_set_flag("ignore_return",
                   ""); // no warnings if the return value is ignored
  __require_allocated_array(s1);
  size1 = __get_array_length(s1);
  __require_allocated_array(s2);
  INFER_EXCLUDE_CONDITION(n > size1);
  return s1;
}
Esempio n. 12
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;
  __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 s1;
}
Esempio n. 13
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;
  __require_allocated_array(s1);
  size1 = __get_array_length(s1);
  __require_allocated_array(s2);
  size2 = __get_array_length(s2);
  INFER_EXCLUDE_CONDITION(size2 > size1);
  return s1;
}
Esempio n. 14
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;
}
Esempio n. 15
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;
}
Esempio n. 16
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;
}
Esempio n. 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 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;
}
Esempio n. 18
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;
}
Esempio n. 19
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;
}
Esempio n. 20
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;
}
Esempio n. 21
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;
}
Esempio n. 22
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;
}
Esempio n. 23
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;
}
Esempio n. 24
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;
}
Esempio n. 25
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;
}
Esempio n. 26
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;
}
Esempio n. 27
0
// modelled using malloc
char* XGetAtomName(void* display, void* atom) {
  int size;
  INFER_EXCLUDE_CONDITION(size <= 0);
  return (char*)malloc(size);
}
Esempio n. 28
0
// modelled as free, requires NONNULL pointer
void XFree(void* ptr) {
  INFER_EXCLUDE_CONDITION(!ptr);
  free(ptr);
}