From f09cda49909e68dd283a2e029f71db29e5e37d5b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 May 2012 03:21:34 +0200 Subject: [PATCH 1/2] libreplace: Fix symbol names for snprintf/asprintf/vasprintf. Autobuild-User: Jelmer Vernooij Autobuild-Date: Sun May 13 05:16:28 CEST 2012 on sn-devel-104 (cherry picked from commit cf67da70c9a63c4dc63f287059321d6c36d1e19e) --- lib/replace/snprintf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/replace/snprintf.c b/lib/replace/snprintf.c index bca7742..877d2a1 100644 --- a/lib/replace/snprintf.c +++ b/lib/replace/snprintf.c @@ -1187,7 +1187,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list, return max; } - int vsnprintf (char *str, size_t count, const char *fmt, va_list args) + int rep_vsnprintf (char *str, size_t count, const char *fmt, va_list args) { return dopr(str, count, fmt, args); } @@ -1200,7 +1200,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list, * that doesn't work properly according to the autoconf test. */ #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF) - int snprintf(char *str,size_t count,const char *fmt,...) + int rep_snprintf(char *str,size_t count,const char *fmt,...) { size_t ret; va_list ap; @@ -1213,7 +1213,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list, #endif #ifndef HAVE_C99_VSNPRINTF - int printf(const char *fmt, ...) + int rep_printf(const char *fmt, ...) { va_list ap; int ret; @@ -1234,7 +1234,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list, #endif #ifndef HAVE_C99_VSNPRINTF - int fprintf(FILE *stream, const char *fmt, ...) + int rep_fprintf(FILE *stream, const char *fmt, ...) { va_list ap; int ret; @@ -1257,7 +1257,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list, #endif #ifndef HAVE_VASPRINTF - int vasprintf(char **ptr, const char *format, va_list ap) + int rep_vasprintf(char **ptr, const char *format, va_list ap) { int ret; va_list ap2; @@ -1280,7 +1280,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list, #ifndef HAVE_ASPRINTF - int asprintf(char **ptr, const char *format, ...) + int rep_asprintf(char **ptr, const char *format, ...) { va_list ap; int ret; -- 1.7.9.5 From ae2806b417b6b110f330496d930a43996a1c9ed0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 13 Nov 2012 14:07:11 +0100 Subject: [PATCH 2/2] lib/replace: replace all *printf function if we replace snprintf (bug #9390) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes segfaults in log level = 10 on Solaris. Signed-off-by: Stefan Metzmacher Signed-off-by: Björn Jacke Autobuild-User(master): Björn Jacke Autobuild-Date(master): Wed Nov 14 19:41:14 CET 2012 on sn-devel-104 (cherry picked from commit a15da3625850d97b3da1b02308c870f820007c52) --- lib/replace/replace.c | 4 ++-- lib/replace/replace.h | 42 ++++++++++++++++++++++++++++++------------ lib/replace/snprintf.c | 5 ++--- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/lib/replace/replace.c b/lib/replace/replace.c index d9a96ff..83fa6b3 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -750,7 +750,7 @@ void *rep_memmem(const void *haystack, size_t haystacklen, } #endif -#ifndef HAVE_VDPRINTF +#if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF) int rep_vdprintf(int fd, const char *format, va_list ap) { char *s = NULL; @@ -767,7 +767,7 @@ int rep_vdprintf(int fd, const char *format, va_list ap) } #endif -#ifndef HAVE_DPRINTF +#if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF) int rep_dprintf(int fd, const char *format, ...) { int ret; diff --git a/lib/replace/replace.h b/lib/replace/replace.h index c47cf1c..926ccc7 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -355,16 +355,6 @@ int rep_dlclose(void *handle); /* prototype is in system/network.h */ #endif -#ifndef HAVE_VDPRINTF -#define vdprintf rep_vdprintf -int rep_vdprintf(int fd, const char *format, va_list ap); -#endif - -#ifndef HAVE_DPRINTF -#define dprintf rep_dprintf -int rep_dprintf(int fd, const char *format, ...); -#endif - #ifndef PRINTF_ATTRIBUTE #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) /** Use gcc attribute to check printf fns. a1 is the 1-based index of @@ -385,7 +375,17 @@ int rep_dprintf(int fd, const char *format, ...); #endif #endif -#ifndef HAVE_VASPRINTF +#if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF) +#define vdprintf rep_vdprintf +int rep_vdprintf(int fd, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); +#endif + +#if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF) +#define dprintf rep_dprintf +int rep_dprintf(int fd, const char *format, ...) PRINTF_ATTRIBUTE(2,3); +#endif + +#if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF) #define vasprintf rep_vasprintf int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); #endif @@ -400,11 +400,29 @@ int rep_snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4); int rep_vsnprintf(char *,size_t ,const char *, va_list ap) PRINTF_ATTRIBUTE(3,0); #endif -#ifndef HAVE_ASPRINTF +#if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF) #define asprintf rep_asprintf int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3); #endif +#if !defined(HAVE_C99_VSNPRINTF) +#ifdef REPLACE_BROKEN_PRINTF +/* + * We do not redefine printf by default + * as it breaks the build if system headers + * use __attribute__((format(printf, 3, 0))) + * instead of __attribute__((format(__printf__, 3, 0))) + */ +#define printf rep_printf +#endif +int rep_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2); +#endif + +#if !defined(HAVE_C99_VSNPRINTF) +#define fprintf rep_fprintf +int rep_fprintf(FILE *stream, const char *, ...) PRINTF_ATTRIBUTE(2,3); +#endif + #ifndef HAVE_VSYSLOG #ifdef HAVE_SYSLOG #define vsyslog rep_vsyslog diff --git a/lib/replace/snprintf.c b/lib/replace/snprintf.c index 877d2a1..6b4a711 100644 --- a/lib/replace/snprintf.c +++ b/lib/replace/snprintf.c @@ -1256,7 +1256,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list, #endif -#ifndef HAVE_VASPRINTF +#if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF) int rep_vasprintf(char **ptr, const char *format, va_list ap) { int ret; @@ -1278,8 +1278,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list, } #endif - -#ifndef HAVE_ASPRINTF +#if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF) int rep_asprintf(char **ptr, const char *format, ...) { va_list ap; -- 1.7.9.5