Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9d6f060

Browse files
committed
Fix for HAVE_LONG bug in snprintf.c.
1 parent 6b7cf13 commit 9d6f060

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

src/backend/port/snprintf.c

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
#include "regex/cdefs.h"
4242

4343
#include <stdarg.h>
44-
#define VA_LOCAL_DECL va_list args;
45-
#define VA_START(f) va_start(args, f)
46-
#define VA_END va_end(args)
4744

4845
#include <sys/ioctl.h>
4946
#include <sys/param.h>
@@ -75,34 +72,30 @@ typedef long long long_long;
7572
* causing nast effects.
7673
**************************************************************/
7774

78-
/*static char _id[] = "$Id: snprintf.c,v 1.12 1998/12/18 06:59:39 momjian Exp $";*/
75+
/*static char _id[] = "$Id: snprintf.c,v 1.13 1998/12/18 07:03:06 momjian Exp $";*/
7976
static char *end;
8077
static int SnprfOverflow;
8178

8279
int snprintf(char *str, size_t count, const char *fmt,...);
83-
int vsnprintf(char *str, size_t count, const char *fmt,...);
84-
static void dopr(char *buffer, const char *format,...);
80+
int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
81+
static void dopr(char *buffer, const char *format, va_list args);
8582

8683
int
8784
snprintf(char *str, size_t count, const char *fmt,...)
8885
{
8986
int len;
87+
va_list args;
9088

91-
VA_LOCAL_DECL
92-
93-
VA_START(fmt);
89+
va_start(args, fmt);
9490
len = vsnprintf(str, count, fmt, args);
95-
VA_END;
91+
va_end(args);
9692
return len;
9793
}
9894

9995

10096
int
101-
vsnprintf(char *str, size_t count, const char *fmt,...)
97+
vsnprintf(char *str, size_t count, const char *fmt, va_list args)
10298
{
103-
VA_LOCAL_DECL
104-
105-
VA_START(fmt);
10699
str[0] = 0;
107100
end = str + count - 1;
108101
SnprfOverflow = 0;
@@ -112,7 +105,6 @@ vsnprintf(char *str, size_t count, const char *fmt,...)
112105
if (SnprfOverflow)
113106
elog(NOTICE, "vsnprintf overflow, len = %d, str = %s",
114107
count, str);
115-
VA_END;
116108
return strlen(str);
117109
}
118110

@@ -122,7 +114,7 @@ vsnprintf(char *str, size_t count, const char *fmt,...)
122114

123115
static void fmtstr __P((char *value, int ljust, int len, int zpad, int maxwidth));
124116

125-
#ifndef HAVE_LONG_LONG_INT_64
117+
#ifndef HAVE_LONG_INT_64
126118
static void fmtnum __P((long value, int base, int dosign, int ljust, int len, int zpad));
127119
#else
128120
static void fmtnum __P((long_long value, int base, int dosign, int ljust, int len, int zpad));
@@ -133,27 +125,23 @@ static char *output;
133125
static void dopr_outch __P((int c));
134126

135127
static void
136-
dopr(char *buffer, const char *format,...)
128+
dopr(char *buffer, const char *format, va_list args)
137129
{
138130
int ch;
139131
#ifdef HAVE_LONG_LONG_INT_64
140132
long_long value;
133+
int longlongflag = 0;
141134
#else
142135
long value;
143136
#endif
144137
int longflag = 0;
145-
int longlongflag = 0;
146138
int pointflag = 0;
147139
int maxwidth = 0;
148140
char *strvalue;
149141
int ljust;
150142
int len;
151143
int zpad;
152144

153-
VA_LOCAL_DECL
154-
155-
VA_START(format);
156-
157145
output = buffer;
158146
while ((ch = *format++))
159147
{
@@ -162,13 +150,15 @@ dopr(char *buffer, const char *format,...)
162150
case '%':
163151
ljust = len = zpad = maxwidth = 0;
164152
longflag = pointflag = 0;
153+
#ifdef HAVE_LONG_LONG_INT_64
154+
longlongflag = 0;
155+
#endif
165156
nextch:
166157
ch = *format++;
167158
switch (ch)
168159
{
169160
case 0:
170161
dostr("**end of format**", 0);
171-
VA_END;
172162
return;
173163
case '-':
174164
ljust = 1;
@@ -200,16 +190,13 @@ dopr(char *buffer, const char *format,...)
200190
pointflag = 1;
201191
goto nextch;
202192
case 'l':
193+
#ifdef HAVE_LONG_LONG_INT_64
203194
if (longflag)
204-
{
205195
longlongflag = 1;
206-
goto nextch;
207-
}
208196
else
209-
{
197+
#endif
210198
longflag = 1;
211-
goto nextch;
212-
}
199+
goto nextch;
213200
case 'u':
214201
case 'U':
215202
/* fmtnum(value,base,dosign,ljust,len,zpad) */
@@ -255,6 +242,7 @@ dopr(char *buffer, const char *format,...)
255242
}
256243
else
257244
value = va_arg(args, int);
245+
258246
fmtnum(value, 10, 1, ljust, len, zpad);
259247
break;
260248
case 'x':
@@ -311,7 +299,6 @@ dopr(char *buffer, const char *format,...)
311299
}
312300
}
313301
*output = 0;
314-
VA_END;
315302
}
316303

317304
static void
@@ -362,7 +349,7 @@ int base,
362349
zpad;
363350
{
364351
int signvalue = 0;
365-
#ifdef HAVE_LONG_LONG_INT_64
352+
#ifdef HAVE_LONG_INT_64
366353
unsigned long_long uvalue;
367354
#else
368355
unsigned long uvalue;

0 commit comments

Comments
 (0)