Skip to content

Commit 25df970

Browse files
committed
CBMC library: fix dead code in pipe()
error was already guaranteed to be 1 in this branch, thus the ?: could not actually produce both return values.
1 parent 55d32b5 commit 25df970

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
#endif
77

88
#include <assert.h>
9+
#include <errno.h>
910

1011
int main()
1112
{
1213
int filedesc[2];
1314

15+
errno = 0;
1416
#ifdef _WIN32
1517
int ret = _pipe(filedesc, 1000, O_BINARY);
1618
#else
1719
int ret = pipe(filedesc);
1820
#endif
1921

22+
__CPROVER_assert(errno != EMFILE, "EMFILE");
23+
__CPROVER_assert(errno != ENFILE, "ENFILE");
24+
2025
__CPROVER_assume(ret == 0);
2126

2227
char data[2] = {7, 42};

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ main.c
33

44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[main\.assertion\.4\] .* assertion data\[1\] == 31: FAILURE$
7-
^\*\* 1 of 5 failed
6+
^\[main\.assertion\.1\] line 22 EMFILE: FAILURE$
7+
^\[main\.assertion\.2\] line 23 ENFILE: FAILURE$
8+
^\[main\.assertion\.6\] .* assertion data\[1\] == 31: FAILURE$
9+
^\*\* 3 of 7 failed
810
--
911
^warning: ignoring

src/ansi-c/library/unistd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int pipe(int fildes[2])
5959
__CPROVER_bool error=__VERIFIER_nondet___CPROVER_bool();
6060
if(error)
6161
{
62-
errno=error==1 ? EMFILE : ENFILE;
62+
errno = __VERIFIER_nondet___CPROVER_bool() ? EMFILE : ENFILE;
6363
return -1;
6464
}
6565

0 commit comments

Comments
 (0)