Skip to content

Commit 3ab9c21

Browse files
committed
C library: implement {v,}dprintf
The model implementation has no side effects, but will make sure that the format string pointer can be dereferenced.
1 parent a8861ed commit 3ab9c21

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
dprintf(1, "some string %s: %d\n", argv[0], 42);
7+
dprintf(1, "some other string\n");
8+
return 0;
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdarg.h>
2+
#include <stdio.h>
3+
4+
int xdprintf(int fd, const char *format, ...)
5+
{
6+
va_list list;
7+
va_start(list, format);
8+
int result = vdprintf(fd, format, list);
9+
va_end(list);
10+
return result;
11+
}
12+
13+
int main()
14+
{
15+
xdprintf(1, "%d\n", 42);
16+
return 0;
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/ansi-c/library/stdio.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,55 @@ __CPROVER_HIDE:;
15401540
return result;
15411541
}
15421542

1543+
/* FUNCTION: dprintf */
1544+
1545+
#ifndef __CPROVER_STDIO_H_INCLUDED
1546+
# include <stdio.h>
1547+
# define __CPROVER_STDIO_H_INCLUDED
1548+
#endif
1549+
1550+
#ifndef __CPROVER_STDARG_H_INCLUDED
1551+
# include <stdarg.h>
1552+
# define __CPROVER_STDARG_H_INCLUDED
1553+
#endif
1554+
1555+
int dprintf(int fd, const char *restrict format, ...)
1556+
{
1557+
__CPROVER_HIDE:;
1558+
va_list list;
1559+
va_start(list, format);
1560+
int result = dprintf(fd, format, list);
1561+
va_end(list);
1562+
return result;
1563+
}
1564+
1565+
/* FUNCTION: vdprintf */
1566+
1567+
#ifndef __CPROVER_STDIO_H_INCLUDED
1568+
# include <stdio.h>
1569+
# define __CPROVER_STDIO_H_INCLUDED
1570+
#endif
1571+
1572+
#ifndef __CPROVER_STDARG_H_INCLUDED
1573+
# include <stdarg.h>
1574+
# define __CPROVER_STDARG_H_INCLUDED
1575+
#endif
1576+
1577+
int __VERIFIER_nondet_int(void);
1578+
1579+
int vdprintf(int fd, const char *restrict format, va_list arg)
1580+
{
1581+
__CPROVER_HIDE:;
1582+
1583+
int result = __VERIFIER_nondet_int();
1584+
1585+
(void)fd;
1586+
(void)*format;
1587+
(void)arg;
1588+
1589+
return result;
1590+
}
1591+
15431592
/* FUNCTION: vasprintf */
15441593

15451594
#ifndef __CPROVER_STDIO_H_INCLUDED

0 commit comments

Comments
 (0)