Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions regression/cbmc-library/rand-01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <assert.h>
#include <stdlib.h>

int main()
{
int r = rand();
assert(r >= 0);
return 0;
}
8 changes: 8 additions & 0 deletions regression/cbmc-library/rand-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --bounds-check
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
10 changes: 10 additions & 0 deletions regression/cbmc-library/rand_r-01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <assert.h>
#include <stdlib.h>

int main()
{
unsigned int seed;
int r = rand_r(&seed);
assert(r >= 0);
return 0;
}
8 changes: 8 additions & 0 deletions regression/cbmc-library/rand_r-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --bounds-check
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
27 changes: 27 additions & 0 deletions src/ansi-c/library/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,30 @@ long random(void)
__CPROVER_assume(result>=0 && result<=2147483647);
return result;
}

/* FUNCTION: rand */

int __VERIFIER_nondet_int();

int rand(void)
{
__CPROVER_HIDE:;
// We return a non-deterministic value instead of a random one.
int result = __VERIFIER_nondet_int();
__CPROVER_assume(result >= 0);
return result;
}

/* FUNCTION: rand_r */

int __VERIFIER_nondet_int();

int rand_r(unsigned int *seed)
{
__CPROVER_HIDE:;
// We return a non-deterministic value instead of a random one.
(void)*seed;
int result = __VERIFIER_nondet_int();
__CPROVER_assume(result >= 0);
return result;
}