Browse Source

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
tags/devuan/2.0.1+devuan1
David Kalnischkies 3 years ago
parent
commit
50920fca5e
1 changed files with 12 additions and 18 deletions
  1. +12
    -18
      test/interactive-helper/libnoprofile.c

+ 12
- 18
test/interactive-helper/libnoprofile.c View File

@@ -7,17 +7,14 @@
#include <stdio.h>

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, ...) {


Loading…
Cancel
Save