Skip to content

C library: implement {v,}dprintf #8238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions regression/cbmc-library/dprintf-01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <assert.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
dprintf(1, "some string %s: %d\n", argv[0], 42);
dprintf(1, "some other string\n");
return 0;
}
8 changes: 8 additions & 0 deletions regression/cbmc-library/dprintf-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --bounds-check
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
17 changes: 17 additions & 0 deletions regression/cbmc-library/vdprintf-01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdarg.h>
#include <stdio.h>

int xdprintf(int fd, const char *format, ...)
{
va_list list;
va_start(list, format);
int result = vdprintf(fd, format, list);
va_end(list);
return result;
}

int main()
{
xdprintf(1, "%d\n", 42);
return 0;
}
8 changes: 8 additions & 0 deletions regression/cbmc-library/vdprintf-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --bounds-check
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
49 changes: 49 additions & 0 deletions src/ansi-c/library/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,55 @@ int asprintf(char **ptr, const char *fmt, ...)
return result;
}

/* FUNCTION: dprintf */

#ifndef __CPROVER_STDIO_H_INCLUDED
# include <stdio.h>
# define __CPROVER_STDIO_H_INCLUDED
#endif

#ifndef __CPROVER_STDARG_H_INCLUDED
# include <stdarg.h>
# define __CPROVER_STDARG_H_INCLUDED
#endif

int dprintf(int fd, const char *restrict format, ...)
{
__CPROVER_HIDE:;
va_list list;
va_start(list, format);
int result = vdprintf(fd, format, list);
va_end(list);
return result;
}

/* FUNCTION: vdprintf */

#ifndef __CPROVER_STDIO_H_INCLUDED
# include <stdio.h>
# define __CPROVER_STDIO_H_INCLUDED
#endif

#ifndef __CPROVER_STDARG_H_INCLUDED
# include <stdarg.h>
# define __CPROVER_STDARG_H_INCLUDED
#endif

int __VERIFIER_nondet_int(void);

int vdprintf(int fd, const char *restrict format, va_list arg)
{
__CPROVER_HIDE:;

int result = __VERIFIER_nondet_int();

(void)fd;
(void)*format;
(void)arg;

return result;
}

/* FUNCTION: vasprintf */

#ifndef __CPROVER_STDIO_H_INCLUDED
Expand Down