lib/replace: replace all *printf function if we replace snprintf (bug #9390)
authorStefan Metzmacher <metze@samba.org>
Tue, 13 Nov 2012 13:07:11 +0000 (14:07 +0100)
committerBjoern Jacke <bj@sernet.de>
Wed, 14 Nov 2012 18:41:14 +0000 (19:41 +0100)
This fixes segfaults in log level = 10 on Solaris.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Björn Jacke <bj@sernet.de>
Autobuild-User(master): Björn Jacke <bj@sernet.de>
Autobuild-Date(master): Wed Nov 14 19:41:14 CET 2012 on sn-devel-104

lib/replace/replace.c
lib/replace/replace.h
lib/replace/snprintf.c

index e461471e5517340f8e414d4193774cef7fc43987..7ee5f4bc1e750b36f4670e67b59bd8be389b6a98 100644 (file)
@@ -741,7 +741,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;
@@ -758,7 +758,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;
index bbea0fc77481057e7c08b16e06f6fa874752bead..cb412c273d188759b4b750e06d6f28572507882e 100644 (file)
@@ -376,16 +376,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
@@ -406,7 +396,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
@@ -421,11 +421,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
index 877d2a1d62b8f46eadd7c6be9cce140d340e21c6..6b4a711045c4c4a5530b3c22f2f5894a48242991 100644 (file)
@@ -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;