Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7767aad

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.cis using vprintf(), which snprintf.c did not provide coverage for.This is not good if we want to have uniform *printf behavior, andit's pretty silly to omit when it's a one-line function.I also noted that snprintf.c has pg_vsprintf() but for some reasonit was not exposed to the outside world, creating another way inwhich code might accidentally invoke the platform *printf family.Let's just make sure that we replace all eight of the POSIX-standardprintf family.Also, upgrade plperl.h and plpython.h to make sure that they dotheir undefine/redefine rain dance for all eight, not some randommaybe-sufficient subset thereof.
1 parent82ff0cc commit7767aad

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
#ifdefsnprintf
153153
#undef snprintf
154154
#endif
155+
#ifdefvsprintf
156+
#undef vsprintf
157+
#endif
155158
#ifdefsprintf
156159
#undef sprintf
157160
#endif
@@ -161,15 +164,20 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
161164
#ifdeffprintf
162165
#undef fprintf
163166
#endif
167+
#ifdefvprintf
168+
#undef vprintf
169+
#endif
164170
#ifdefprintf
165171
#undef printf
166172
#endif
167173

168174
externintpg_vsnprintf(char*str,size_tcount,constchar*fmt,va_listargs);
169175
externintpg_snprintf(char*str,size_tcount,constchar*fmt,...)pg_attribute_printf(3,4);
176+
externintpg_vsprintf(char*str,constchar*fmt,va_listargs);
170177
externintpg_sprintf(char*str,constchar*fmt,...)pg_attribute_printf(2,3);
171178
externintpg_vfprintf(FILE*stream,constchar*fmt,va_listargs);
172179
externintpg_fprintf(FILE*stream,constchar*fmt,...)pg_attribute_printf(2,3);
180+
externintpg_vprintf(constchar*fmt,va_listargs);
173181
externintpg_printf(constchar*fmt,...)pg_attribute_printf(1,2);
174182

175183
/*
@@ -182,9 +190,11 @@ extern intpg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
182190
*/
183191
#definevsnprintfpg_vsnprintf
184192
#definesnprintfpg_snprintf
193+
#definevsprintfpg_vsprintf
185194
#definesprintfpg_sprintf
186195
#definevfprintfpg_vfprintf
187196
#definefprintfpg_fprintf
197+
#definevprintfpg_vprintf
188198
#defineprintf(...)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+
#ifdefvsnprintf
105+
#undef vsnprintf
106+
#endif
99107
#ifdefsnprintf
100108
#undef snprintf
101109
#endif
102-
#ifdefvsnprintf
103-
#undef vsnprintf
110+
#ifdefvsprintf
111+
#undef vsprintf
112+
#endif
113+
#ifdefsprintf
114+
#undef sprintf
115+
#endif
116+
#ifdefvfprintf
117+
#undef vfprintf
104118
#endif
119+
#ifdeffprintf
120+
#undef fprintf
121+
#endif
122+
#ifdefvprintf
123+
#undef vprintf
124+
#endif
125+
#ifdefprintf
126+
#undef printf
127+
#endif
128+
105129
#definevsnprintfpg_vsnprintf
106130
#definesnprintfpg_snprintf
131+
#definevsprintfpg_vsprintf
132+
#definesprintfpg_sprintf
133+
#definevfprintfpg_vfprintf
134+
#definefprintfpg_fprintf
135+
#definevprintfpg_vprintf
136+
#defineprintf(...)pg_printf(__VA_ARGS__)
107137

108138
/* perl version and platform portability */
109139
#defineNEED_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+
#ifdefvsnprintf
131+
#undef vsnprintf
132+
#endif
124133
#ifdefsnprintf
125134
#undef snprintf
126135
#endif
127-
#ifdefvsnprintf
128-
#undefvsnprintf
136+
#ifdefvsprintf
137+
#undefvsprintf
129138
#endif
130-
#definevsnprintfpg_vsnprintf
131-
#definesnprintfpg_snprintf
139+
#ifdefsprintf
140+
#undef sprintf
141+
#endif
142+
#ifdefvfprintf
143+
#undef vfprintf
144+
#endif
145+
#ifdeffprintf
146+
#undef fprintf
147+
#endif
148+
#ifdefvprintf
149+
#undef vprintf
150+
#endif
151+
#ifdefprintf
152+
#undef printf
153+
#endif
154+
155+
#definevsnprintfpg_vsnprintf
156+
#definesnprintfpg_snprintf
157+
#definevsprintfpg_vsprintf
158+
#definesprintfpg_sprintf
159+
#definevfprintfpg_vfprintf
160+
#definefprintfpg_fprintf
161+
#definevprintfpg_vprintf
162+
#defineprintf(...)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
#undefvsnprintf
104104
#undefsnprintf
105+
#undefvsprintf
105106
#undefsprintf
106107
#undefvfprintf
107108
#undeffprintf
109+
#undefvprintf
108110
#undefprintf
109111

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

211-
staticint
213+
int
212214
pg_vsprintf(char*str,constchar*fmt,va_listargs)
213215
{
214216
PrintfTargettarget;
@@ -270,6 +272,12 @@ pg_fprintf(FILE *stream, const char *fmt,...)
270272
returnlen;
271273
}
272274

275+
int
276+
pg_vprintf(constchar*fmt,va_listargs)
277+
{
278+
returnpg_vfprintf(stdout,fmt,args);
279+
}
280+
273281
int
274282
pg_printf(constchar*fmt,...)
275283
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp