From 50920fca5eff021f810d5de0cc9d2fa4d6068c50 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 5 Oct 2017 14:49:27 +0200 Subject: remove pointless va_copy to avoid cleanup dance A va_copy call needs to be closed in all branches with va_end, so these functions would need to be reworked slightly, but we don't actually need to copy the va_list as we don't work on it, we just push it forward, so dropping the copy and everyone is happy. Reported-By: cppcheck Gbp-Dch: Ignore --- test/interactive-helper/libnoprofile.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/interactive-helper/libnoprofile.c b/test/interactive-helper/libnoprofile.c index 2cba6dc8b..f11b89899 100644 --- a/test/interactive-helper/libnoprofile.c +++ b/test/interactive-helper/libnoprofile.c @@ -7,17 +7,14 @@ #include int vprintf(const char *format, va_list ap) { - static int (*func_fprintf)(const char *format, va_list ap) = NULL; - if (func_fprintf == NULL) - func_fprintf = (int (*) (const char *format, va_list ap)) dlsym(RTLD_NEXT, "vprintf"); - - va_list ap2; - va_copy(ap2, ap); if (strncmp(format, "profiling:", strlen("profiling:")) == 0) return 0; - int res = func_fprintf(format, ap2); - va_end(ap2); - return res; + + static int (*func_fprintf)(const char *format, va_list ap) = NULL; + if (func_fprintf == NULL) + func_fprintf = (int (*)(const char *format, va_list ap))dlsym(RTLD_NEXT, "vprintf"); + + return func_fprintf(format, ap); } int printf(const char *format, ...) { va_list ap; @@ -28,17 +25,14 @@ int printf(const char *format, ...) { } int vfprintf(FILE *stream, const char *format, va_list ap) { - static int (*func_vfprintf)(FILE *stream, const char *format, va_list ap) = NULL; - if (func_vfprintf == NULL) - func_vfprintf = (int (*) (FILE *stream, const char *format, va_list ap)) dlsym(RTLD_NEXT, "vfprintf"); - - va_list ap2; - va_copy(ap2, ap); if (strncmp(format, "profiling:", strlen("profiling:")) == 0) return 0; - int res = func_vfprintf(stream, format, ap2); - va_end(ap2); - return res; + + static int (*func_vfprintf)(FILE * stream, const char *format, va_list ap) = NULL; + if (func_vfprintf == NULL) + func_vfprintf = (int (*)(FILE * stream, const char *format, va_list ap))dlsym(RTLD_NEXT, "vfprintf"); + + return func_vfprintf(stream, format, ap); } int fprintf(FILE *stream, const char *format, ...) { -- cgit v1.2.3