Skip to content

Commit 6886712

Browse files
committed
simplified buffer precondition in fgets
Since we are interested in checking if the buffer is writable and we are assuming that str_length < size, verify __CPROVER_w_ok(str, str_length + 1) is the same as verify __CPROVER_w_ok(str, size).
1 parent b245ff1 commit 6886712

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/ansi-c/library/stdio.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ char *fgets(char *str, int size, FILE *stream)
260260
{
261261
int str_length=__VERIFIER_nondet_int();
262262
__CPROVER_assume(str_length >= 0 && str_length < size);
263-
// check that the memory is accessible
264-
__CPROVER_precondition(
265-
__CPROVER_w_ok(str, str_length + 1), "fgets buffer writeable");
263+
__CPROVER_precondition(__CPROVER_w_ok(str, size), "fgets buffer writable");
266264
char contents_nondet[str_length];
267265
__CPROVER_array_replace(str, contents_nondet);
268266
if(!error)

0 commit comments

Comments
 (0)