Skip to content

Commit 2d63a71

Browse files
authored
Merge pull request #8238 from tautschnig/features/dprintf
C library: implement {v,}dprintf
2 parents c08e473 + 6aeace1 commit 2d63a71

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed
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+
}
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
+17
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+
}
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

+49
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,55 @@ int asprintf(char **ptr, const char *fmt, ...)
15601560
return result;
15611561
}
15621562

1563+
/* FUNCTION: dprintf */
1564+
1565+
#ifndef __CPROVER_STDIO_H_INCLUDED
1566+
# include <stdio.h>
1567+
# define __CPROVER_STDIO_H_INCLUDED
1568+
#endif
1569+
1570+
#ifndef __CPROVER_STDARG_H_INCLUDED
1571+
# include <stdarg.h>
1572+
# define __CPROVER_STDARG_H_INCLUDED
1573+
#endif
1574+
1575+
int dprintf(int fd, const char *restrict format, ...)
1576+
{
1577+
__CPROVER_HIDE:;
1578+
va_list list;
1579+
va_start(list, format);
1580+
int result = vdprintf(fd, format, list);
1581+
va_end(list);
1582+
return result;
1583+
}
1584+
1585+
/* FUNCTION: vdprintf */
1586+
1587+
#ifndef __CPROVER_STDIO_H_INCLUDED
1588+
# include <stdio.h>
1589+
# define __CPROVER_STDIO_H_INCLUDED
1590+
#endif
1591+
1592+
#ifndef __CPROVER_STDARG_H_INCLUDED
1593+
# include <stdarg.h>
1594+
# define __CPROVER_STDARG_H_INCLUDED
1595+
#endif
1596+
1597+
int __VERIFIER_nondet_int(void);
1598+
1599+
int vdprintf(int fd, const char *restrict format, va_list arg)
1600+
{
1601+
__CPROVER_HIDE:;
1602+
1603+
int result = __VERIFIER_nondet_int();
1604+
1605+
(void)fd;
1606+
(void)*format;
1607+
(void)arg;
1608+
1609+
return result;
1610+
}
1611+
15631612
/* FUNCTION: vasprintf */
15641613

15651614
#ifndef __CPROVER_STDIO_H_INCLUDED

0 commit comments

Comments
 (0)