Commit 7767aadd authored by Tom Lane's avatar Tom Lane

Fix omissions in snprintf.c's coverage of standard *printf functions.

A warning on a NetBSD box revealed to me that pg_waldump/compat.c
is using vprintf(), which snprintf.c did not provide coverage for.
This is not good if we want to have uniform *printf behavior, and
it's pretty silly to omit when it's a one-line function.

I also noted that snprintf.c has pg_vsprintf() but for some reason
it was not exposed to the outside world, creating another way in
which code might accidentally invoke the platform *printf family.

Let's just make sure that we replace all eight of the POSIX-standard
printf family.

Also, upgrade plperl.h and plpython.h to make sure that they do
their undefine/redefine rain dance for all eight, not some random
maybe-sufficient subset thereof.
parent 82ff0cc9
...@@ -152,6 +152,9 @@ extern unsigned char pg_ascii_tolower(unsigned char ch); ...@@ -152,6 +152,9 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
#ifdef snprintf #ifdef snprintf
#undef snprintf #undef snprintf
#endif #endif
#ifdef vsprintf
#undef vsprintf
#endif
#ifdef sprintf #ifdef sprintf
#undef sprintf #undef sprintf
#endif #endif
...@@ -161,15 +164,20 @@ extern unsigned char pg_ascii_tolower(unsigned char ch); ...@@ -161,15 +164,20 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
#ifdef fprintf #ifdef fprintf
#undef fprintf #undef fprintf
#endif #endif
#ifdef vprintf
#undef vprintf
#endif
#ifdef printf #ifdef printf
#undef printf #undef printf
#endif #endif
extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args); extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
extern int pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4); extern int pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
extern int pg_vsprintf(char *str, const char *fmt, va_list args);
extern int pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3); extern int pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args); extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args);
extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3); extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
extern int pg_vprintf(const char *fmt, va_list args);
extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2); extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
/* /*
...@@ -182,9 +190,11 @@ extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2); ...@@ -182,9 +190,11 @@ extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
*/ */
#define vsnprintf pg_vsnprintf #define vsnprintf pg_vsnprintf
#define snprintf pg_snprintf #define snprintf pg_snprintf
#define vsprintf pg_vsprintf
#define sprintf pg_sprintf #define sprintf pg_sprintf
#define vfprintf pg_vfprintf #define vfprintf pg_vfprintf
#define fprintf pg_fprintf #define fprintf pg_fprintf
#define vprintf pg_vprintf
#define printf(...) pg_printf(__VA_ARGS__) #define printf(...) pg_printf(__VA_ARGS__)
/* This is also provided by snprintf.c */ /* This is also provided by snprintf.c */
......
...@@ -29,8 +29,14 @@ ...@@ -29,8 +29,14 @@
* Sometimes perl carefully scribbles on our *printf macros. * Sometimes perl carefully scribbles on our *printf macros.
* So we undefine them here and redefine them after it's done its dirty deed. * So we undefine them here and redefine them after it's done its dirty deed.
*/ */
#undef snprintf
#undef vsnprintf #undef vsnprintf
#undef snprintf
#undef vsprintf
#undef sprintf
#undef vfprintf
#undef fprintf
#undef vprintf
#undef printf
/* /*
* ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's * ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's
...@@ -89,21 +95,45 @@ ...@@ -89,21 +95,45 @@
#undef socket #undef socket
#undef stat #undef stat
#undef unlink #undef unlink
#undef vfprintf
#endif #endif
#include "XSUB.h" #include "XSUB.h"
#endif #endif
/* put back our snprintf and vsnprintf */ /* put back our *printf macros ... this must match src/include/port.h */
#ifdef vsnprintf
#undef vsnprintf
#endif
#ifdef snprintf #ifdef snprintf
#undef snprintf #undef snprintf
#endif #endif
#ifdef vsnprintf #ifdef vsprintf
#undef vsnprintf #undef vsprintf
#endif
#ifdef sprintf
#undef sprintf
#endif
#ifdef vfprintf
#undef vfprintf
#endif #endif
#ifdef fprintf
#undef fprintf
#endif
#ifdef vprintf
#undef vprintf
#endif
#ifdef printf
#undef printf
#endif
#define vsnprintf pg_vsnprintf #define vsnprintf pg_vsnprintf
#define snprintf pg_snprintf #define snprintf pg_snprintf
#define vsprintf pg_vsprintf
#define sprintf pg_sprintf
#define vfprintf pg_vfprintf
#define fprintf pg_fprintf
#define vprintf pg_vprintf
#define printf(...) pg_printf(__VA_ARGS__)
/* perl version and platform portability */ /* perl version and platform portability */
#define NEED_eval_pv #define NEED_eval_pv
......
...@@ -33,8 +33,14 @@ ...@@ -33,8 +33,14 @@
* Sometimes python carefully scribbles on our *printf macros. * Sometimes python carefully scribbles on our *printf macros.
* So we undefine them here and redefine them after it's done its dirty deed. * So we undefine them here and redefine them after it's done its dirty deed.
*/ */
#undef snprintf
#undef vsnprintf #undef vsnprintf
#undef snprintf
#undef vsprintf
#undef sprintf
#undef vfprintf
#undef fprintf
#undef vprintf
#undef printf
#if defined(_MSC_VER) && defined(_DEBUG) #if defined(_MSC_VER) && defined(_DEBUG)
/* Python uses #pragma to bring in a non-default libpython on VC++ if /* Python uses #pragma to bring in a non-default libpython on VC++ if
...@@ -120,15 +126,40 @@ typedef int Py_ssize_t; ...@@ -120,15 +126,40 @@ typedef int Py_ssize_t;
#include <compile.h> #include <compile.h>
#include <eval.h> #include <eval.h>
/* put back our snprintf and vsnprintf */ /* put back our *printf macros ... this must match src/include/port.h */
#ifdef vsnprintf
#undef vsnprintf
#endif
#ifdef snprintf #ifdef snprintf
#undef snprintf #undef snprintf
#endif #endif
#ifdef vsnprintf #ifdef vsprintf
#undef vsnprintf #undef vsprintf
#endif #endif
#define vsnprintf pg_vsnprintf #ifdef sprintf
#define snprintf pg_snprintf #undef sprintf
#endif
#ifdef vfprintf
#undef vfprintf
#endif
#ifdef fprintf
#undef fprintf
#endif
#ifdef vprintf
#undef vprintf
#endif
#ifdef printf
#undef printf
#endif
#define vsnprintf pg_vsnprintf
#define snprintf pg_snprintf
#define vsprintf pg_vsprintf
#define sprintf pg_sprintf
#define vfprintf pg_vfprintf
#define fprintf pg_fprintf
#define vprintf pg_vprintf
#define printf(...) pg_printf(__VA_ARGS__)
/* /*
* Used throughout, and also by the Python 2/3 porting layer, so it's easier to * Used throughout, and also by the Python 2/3 porting layer, so it's easier to
......
...@@ -102,9 +102,11 @@ ...@@ -102,9 +102,11 @@
/* Prevent recursion */ /* Prevent recursion */
#undef vsnprintf #undef vsnprintf
#undef snprintf #undef snprintf
#undef vsprintf
#undef sprintf #undef sprintf
#undef vfprintf #undef vfprintf
#undef fprintf #undef fprintf
#undef vprintf
#undef printf #undef printf
/* /*
...@@ -208,7 +210,7 @@ pg_snprintf(char *str, size_t count, const char *fmt,...) ...@@ -208,7 +210,7 @@ pg_snprintf(char *str, size_t count, const char *fmt,...)
return len; return len;
} }
static int int
pg_vsprintf(char *str, const char *fmt, va_list args) pg_vsprintf(char *str, const char *fmt, va_list args)
{ {
PrintfTarget target; PrintfTarget target;
...@@ -270,6 +272,12 @@ pg_fprintf(FILE *stream, const char *fmt,...) ...@@ -270,6 +272,12 @@ pg_fprintf(FILE *stream, const char *fmt,...)
return len; return len;
} }
int
pg_vprintf(const char *fmt, va_list args)
{
return pg_vfprintf(stdout, fmt, args);
}
int int
pg_printf(const char *fmt,...) pg_printf(const char *fmt,...)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment