Skip to content

Commit

Permalink
Add vprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin committed Sep 30, 2023
1 parent 160298c commit 76fef96
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
19 changes: 18 additions & 1 deletion include/stdio.h
Expand Up @@ -36,9 +36,10 @@ extern "C" {
#undef fread
#undef fwrite
#undef popen
#undef printf
#undef vprintf
#undef vsnprintf
#undef vsprintf
#undef printf

__access(read_only, 2)
#if __has_builtin(__builtin_fdopen)
Expand Down Expand Up @@ -183,6 +184,22 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
#endif
}

#ifndef __clang__ /* FIXME */
__access(read_only, 1)
__format(printf, 1, 0)
#if __has_builtin(__builtin_vprintf)
__diagnose_as_builtin(__builtin_vprintf, 1, 2)
#endif
_FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v)
{
#if __has_builtin(__builtin___vprintf_chk) && USE_NATIVE_CHK
return __builtin___vprintf_chk(_FORTIFY_SOURCE, __f, __v);
#else
return __orig_vprintf(__f, __v);
#endif
}
#endif


#if __has_builtin(__builtin_va_arg_pack)

Expand Down
1 change: 1 addition & 0 deletions tests/Makefile
Expand Up @@ -113,6 +113,7 @@ RUNTIME_TARGETS= \
test_vsnprintf_dynamic \
test_vsnprintf_static \
test_vsprintf \
test_vprintf \
test_wcscat_static_write \
test_wcscpy_static_write \
test_wcsncat_static_write \
Expand Down
16 changes: 16 additions & 0 deletions tests/test_vprintf.c
@@ -0,0 +1,16 @@
#include "common.h"

#include <stdarg.h>
#include <stdio.h>

void wrap(char *format, ...) {
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}


int main(int argc, char** argv) {
wrap("%s", "1234567");
}

0 comments on commit 76fef96

Please sign in to comment.