Skip to content

Commit 10ab557

Browse files
committed
bugfix: pointer check failure in fgets
Now we assume str_length greater than 0, since no dereference should take place when str_length equals 0. Updated cbmc-library/fgets-01 regression test. Fixes: #4621
1 parent 70cfdd5 commit 10ab557

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ main.c
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
77
\[main.assertion.3\] line 16 assertion p\[1\] == 'b': FAILURE
8-
\*\* 2 of \d+ failed
8+
\*\* 1 of \d+ failed
99
--
1010
^warning: ignoring

src/ansi-c/library/stdio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ char *fgets(char *str, int size, FILE *stream)
259259
if(size>0)
260260
{
261261
int str_length=__VERIFIER_nondet_int();
262-
__CPROVER_assume(str_length>=0 && str_length<size);
262+
__CPROVER_assume(str_length>0 && str_length<size);
263263
// check that the memory is accessible
264264
(void)*(char *)str;
265265
(void)*(((const char *)str) + str_length - 1);

0 commit comments

Comments
 (0)