Skip to content

Commit 20ea09a

Browse files
committed
C library: Constrain the return value of fileno and test it
The earlier commit made sure it returns 0/1/2 for stdin/stdout/stderr.
1 parent 3f1ea29 commit 20ea09a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

regression/cbmc-library/fileno-01/main.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
int main()
55
{
6-
fileno();
7-
assert(0);
6+
assert(fileno(stdin) == 0);
7+
assert(fileno(stdout) == 1);
8+
assert(fileno(stderr) == 2);
9+
10+
FILE *some_file;
11+
assert(fileno(some_file) >= -1);
12+
813
return 0;
914
}

regression/cbmc-library/fileno-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

src/ansi-c/library/stdio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ int __VERIFIER_nondet_int();
391391

392392
inline int fileno(FILE *stream)
393393
{
394-
// just return nondet
395394
__CPROVER_HIDE:;
396395
if(stream == stdin)
397396
return 0;
@@ -401,6 +400,7 @@ __CPROVER_HIDE:;
401400
return 2;
402401

403402
int return_value=__VERIFIER_nondet_int();
403+
__CPROVER_assume(return_value >= -1);
404404

405405
#if !defined(__linux__) || defined(__GLIBC__)
406406
(void)*stream;

0 commit comments

Comments
 (0)