Skip to content

Commit b0c09e3

Browse files
authored
Merge pull request #7176 from tautschnig/feature/fscanf
C library: fscanf for modern glibc
2 parents 8f4a19a + f2ac528 commit b0c09e3

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

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

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

44
int main()
55
{
6-
fscanf();
7-
assert(0);
6+
FILE *f = fopen("main.c", "r");
7+
if(f == NULL)
8+
return 1;
9+
char dest[10];
10+
int result = fscanf(f, "%s", dest);
11+
assert(result == 1);
812
return 0;
913
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
KNOWNBUG
22
main.c
3-
--pointer-check --bounds-check
3+
--pointer-check --bounds-check --string-abstraction
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
88
^warning: ignoring
9+
--
10+
This test demonstrates a bug in string abstraction which appears to introduce a
11+
type inconsistency that trips up the simplifier.

src/ansi-c/library/stdio.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,28 @@ __CPROVER_HIDE:;
844844
return result;
845845
}
846846

847+
/* FUNCTION: __isoc99_fscanf */
848+
849+
#ifndef __CPROVER_STDIO_H_INCLUDED
850+
# include <stdio.h>
851+
# define __CPROVER_STDIO_H_INCLUDED
852+
#endif
853+
854+
#ifndef __CPROVER_STDARG_H_INCLUDED
855+
# include <stdarg.h>
856+
# define __CPROVER_STDARG_H_INCLUDED
857+
#endif
858+
859+
int __isoc99_fscanf(FILE *restrict stream, const char *restrict format, ...)
860+
{
861+
__CPROVER_HIDE:;
862+
va_list list;
863+
va_start(list, format);
864+
int result = vfscanf(stream, format, list);
865+
va_end(list);
866+
return result;
867+
}
868+
847869
/* FUNCTION: scanf */
848870

849871
#ifndef __CPROVER_STDIO_H_INCLUDED

src/goto-programs/string_instrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void string_instrumentationt::do_function_call(
251251
do_sprintf(dest, target, lhs, arguments);
252252
else if(identifier=="snprintf")
253253
do_snprintf(dest, target, lhs, arguments);
254-
else if(identifier=="fscanf")
254+
else if(identifier == "fscanf" || identifier == "__isoc99_fscanf")
255255
do_fscanf(dest, target, lhs, arguments);
256256

257257
remove_skip(dest);

0 commit comments

Comments
 (0)