Skip to content

Commit 7767aad

Browse files
committed
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.
1 parent 82ff0cc commit 7767aad

File tree

4 files changed

+91
-12
lines changed

4 files changed

+91
-12
lines changed

src/include/port.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
152152
#ifdef snprintf
153153
#undef snprintf
154154
#endif
155+
#ifdef vsprintf
156+
#undef vsprintf
157+
#endif
155158
#ifdef sprintf
156159
#undef sprintf
157160
#endif
@@ -161,15 +164,20 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
161164
#ifdef fprintf
162165
#undef fprintf
163166
#endif
167+
#ifdef vprintf
168+
#undef vprintf
169+
#endif
164170
#ifdef printf
165171
#undef printf
166172
#endif
167173

168174
extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
169175
extern int pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
176+
extern int pg_vsprintf(char *str, const char *fmt, va_list args);
170177
extern int pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
171178
extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args);
172179
extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
180+
extern int pg_vprintf(const char *fmt, va_list args);
173181
extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
174182

175183
/*
@@ -182,9 +190,11 @@ extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
182190
*/
183191
#define vsnprintf pg_vsnprintf
184192
#define snprintf pg_snprintf
193+
#define vsprintf pg_vsprintf
185194
#define sprintf pg_sprintf
186195
#define vfprintf pg_vfprintf
187196
#define fprintf pg_fprintf
197+
#define vprintf pg_vprintf
188198
#define printf(...) pg_printf(__VA_ARGS__)
189199

190200
/* This is also provided by snprintf.c */

src/pl/plperl/plperl.h

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@
2929
* Sometimes perl carefully scribbles on our *printf macros.
3030
* So we undefine them here and redefine them after it's done its dirty deed.
3131
*/
32-
#undef snprintf
3332
#undef vsnprintf
33+
#undef snprintf
34+
#undef vsprintf
35+
#undef sprintf
36+
#undef vfprintf
37+
#undef fprintf
38+
#undef vprintf
39+
#undef printf
3440

3541
/*
3642
* ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's
@@ -89,21 +95,45 @@
8995
#undef socket
9096
#undef stat
9197
#undef unlink
92-
#undef vfprintf
9398
#endif
9499

95100
#include "XSUB.h"
96101
#endif
97102

98-
/* put back our snprintf and vsnprintf */
103+
/* put back our *printf macros ... this must match src/include/port.h */
104+
#ifdef vsnprintf
105+
#undef vsnprintf
106+
#endif
99107
#ifdef snprintf
100108
#undef snprintf
101109
#endif
102-
#ifdef vsnprintf
103-
#undef vsnprintf
110+
#ifdef vsprintf
111+
#undef vsprintf
112+
#endif
113+
#ifdef sprintf
114+
#undef sprintf
115+
#endif
116+
#ifdef vfprintf
117+
#undef vfprintf
104118
#endif
119+
#ifdef fprintf
120+
#undef fprintf
121+
#endif
122+
#ifdef vprintf
123+
#undef vprintf
124+
#endif
125+
#ifdef printf
126+
#undef printf
127+
#endif
128+
105129
#define vsnprintf pg_vsnprintf
106130
#define snprintf pg_snprintf
131+
#define vsprintf pg_vsprintf
132+
#define sprintf pg_sprintf
133+
#define vfprintf pg_vfprintf
134+
#define fprintf pg_fprintf
135+
#define vprintf pg_vprintf
136+
#define printf(...) pg_printf(__VA_ARGS__)
107137

108138
/* perl version and platform portability */
109139
#define NEED_eval_pv

src/pl/plpython/plpython.h

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@
3333
* Sometimes python carefully scribbles on our *printf macros.
3434
* So we undefine them here and redefine them after it's done its dirty deed.
3535
*/
36-
#undef snprintf
3736
#undef vsnprintf
37+
#undef snprintf
38+
#undef vsprintf
39+
#undef sprintf
40+
#undef vfprintf
41+
#undef fprintf
42+
#undef vprintf
43+
#undef printf
3844

3945
#if defined(_MSC_VER) && defined(_DEBUG)
4046
/* Python uses #pragma to bring in a non-default libpython on VC++ if
@@ -120,15 +126,40 @@ typedef int Py_ssize_t;
120126
#include <compile.h>
121127
#include <eval.h>
122128

123-
/* put back our snprintf and vsnprintf */
129+
/* put back our *printf macros ... this must match src/include/port.h */
130+
#ifdef vsnprintf
131+
#undef vsnprintf
132+
#endif
124133
#ifdef snprintf
125134
#undef snprintf
126135
#endif
127-
#ifdef vsnprintf
128-
#undef vsnprintf
136+
#ifdef vsprintf
137+
#undef vsprintf
129138
#endif
130-
#define vsnprintf pg_vsnprintf
131-
#define snprintf pg_snprintf
139+
#ifdef sprintf
140+
#undef sprintf
141+
#endif
142+
#ifdef vfprintf
143+
#undef vfprintf
144+
#endif
145+
#ifdef fprintf
146+
#undef fprintf
147+
#endif
148+
#ifdef vprintf
149+
#undef vprintf
150+
#endif
151+
#ifdef printf
152+
#undef printf
153+
#endif
154+
155+
#define vsnprintf pg_vsnprintf
156+
#define snprintf pg_snprintf
157+
#define vsprintf pg_vsprintf
158+
#define sprintf pg_sprintf
159+
#define vfprintf pg_vfprintf
160+
#define fprintf pg_fprintf
161+
#define vprintf pg_vprintf
162+
#define printf(...) pg_printf(__VA_ARGS__)
132163

133164
/*
134165
* Used throughout, and also by the Python 2/3 porting layer, so it's easier to

src/port/snprintf.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@
102102
/* Prevent recursion */
103103
#undef vsnprintf
104104
#undef snprintf
105+
#undef vsprintf
105106
#undef sprintf
106107
#undef vfprintf
107108
#undef fprintf
109+
#undef vprintf
108110
#undef printf
109111

110112
/*
@@ -208,7 +210,7 @@ pg_snprintf(char *str, size_t count, const char *fmt,...)
208210
return len;
209211
}
210212

211-
static int
213+
int
212214
pg_vsprintf(char *str, const char *fmt, va_list args)
213215
{
214216
PrintfTarget target;
@@ -270,6 +272,12 @@ pg_fprintf(FILE *stream, const char *fmt,...)
270272
return len;
271273
}
272274

275+
int
276+
pg_vprintf(const char *fmt, va_list args)
277+
{
278+
return pg_vfprintf(stdout, fmt, args);
279+
}
280+
273281
int
274282
pg_printf(const char *fmt,...)
275283
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy