Skip to content

Commit b245ff1

Browse files
committed
remove explicit pointer dereference in fgets
Now, a w_ok precondition is used to check if the buffer is writable.
1 parent 10ab557 commit b245ff1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/ansi-c/library/stdio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ 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
264-
(void)*(char *)str;
265-
(void)*(((const char *)str) + str_length - 1);
264+
__CPROVER_precondition(
265+
__CPROVER_w_ok(str, str_length + 1), "fgets buffer writeable");
266266
char contents_nondet[str_length];
267267
__CPROVER_array_replace(str, contents_nondet);
268268
if(!error)

0 commit comments

Comments
 (0)