@@ -82,24 +82,22 @@ typedef unsigned long ulong_long;
8282 * for string length. This covers a nasty loophole.
8383 *
8484 * The other functions are there to prevent NULL pointers from
85- * causingnast effects.
85+ * causingnasty effects.
8686 **************************************************************/
8787
88- /*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.7 2005/02/28 14:16:16 momjian Exp $";*/
89- static char * end ;
90- static int SnprfOverflow ;
88+ /*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.8 2005/03/01 00:38:11 momjian Exp $";*/
9189
9290int snprintf (char * str ,size_t count ,const char * fmt ,...);
9391int vsnprintf (char * str ,size_t count ,const char * fmt ,va_list args );
9492int printf (const char * format , ...);
95- static void dopr (char * buffer ,const char * format ,va_list args );
93+ static void dopr (char * buffer ,const char * format ,va_list args , char * end );
9694
9795int
9896printf (const char * fmt ,...)
9997{
10098int len ;
10199va_list args ;
102- static char * buffer [4096 ];
100+ char * buffer [4096 ];
103101char * p ;
104102
105103va_start (args ,fmt );
@@ -127,10 +125,10 @@ snprintf(char *str, size_t count, const char *fmt,...)
127125int
128126vsnprintf (char * str ,size_t count ,const char * fmt ,va_list args )
129127{
128+ char * end ;
130129str [0 ]= '\0' ;
131130end = str + count - 1 ;
132- SnprfOverflow = 0 ;
133- dopr (str ,fmt ,args );
131+ dopr (str ,fmt ,args ,end );
134132if (count > 0 )
135133end [0 ]= '\0' ;
136134return strlen (str );
@@ -140,11 +138,11 @@ vsnprintf(char *str, size_t count, const char *fmt, va_list args)
140138 * dopr(): poor man's version of doprintf
141139 */
142140
143- static void fmtstr (char * value ,int ljust ,int len ,int zpad ,int maxwidth );
144- static void fmtnum (long_long value ,int base ,int dosign ,int ljust ,int len ,int zpad );
145- static void fmtfloat (double value ,char type ,int ljust ,int len ,int precision ,int pointflag );
146- static void dostr (char * str ,int cut );
147- static void dopr_outch (int c );
141+ static void fmtstr (char * value ,int ljust ,int len ,int zpad ,int maxwidth , char * end );
142+ static void fmtnum (long_long value ,int base ,int dosign ,int ljust ,int len ,int zpad , char * end );
143+ static void fmtfloat (double value ,char type ,int ljust ,int len ,int precision ,int pointflag , char * end );
144+ static void dostr (char * str ,int cut , char * end );
145+ static void dopr_outch (int c , char * end );
148146
149147static char * output ;
150148
@@ -154,7 +152,7 @@ static char *output;
154152#define FMTCHAR 4
155153
156154static void
157- dopr (char * buffer ,const char * format ,va_list args )
155+ dopr (char * buffer ,const char * format ,va_list args , char * end )
158156{
159157int ch ;
160158long_long value ;
@@ -417,11 +415,11 @@ dopr(char *buffer, const char *format, va_list args)
417415case '%' :
418416break ;
419417default :
420- dostr ("???????" ,0 );
418+ dostr ("???????" ,0 , end );
421419}
422420break ;
423421default :
424- dopr_outch (ch );
422+ dopr_outch (ch , end );
425423break ;
426424}
427425}
@@ -448,27 +446,28 @@ dopr(char *buffer, const char *format, va_list args)
448446case FMTSTR :
449447fmtstr (fmtparptr [i ]-> value ,fmtparptr [i ]-> ljust ,
450448fmtparptr [i ]-> len ,fmtparptr [i ]-> zpad ,
451- fmtparptr [i ]-> maxwidth );
449+ fmtparptr [i ]-> maxwidth , end );
452450break ;
453451case FMTNUM :
454452fmtnum (fmtparptr [i ]-> numvalue ,fmtparptr [i ]-> base ,
455453fmtparptr [i ]-> dosign ,fmtparptr [i ]-> ljust ,
456- fmtparptr [i ]-> len ,fmtparptr [i ]-> zpad );
454+ fmtparptr [i ]-> len ,fmtparptr [i ]-> zpad , end );
457455break ;
458456case FMTFLOAT :
459457fmtfloat (fmtparptr [i ]-> fvalue ,fmtparptr [i ]-> type ,
460458fmtparptr [i ]-> ljust ,fmtparptr [i ]-> len ,
461- fmtparptr [i ]-> precision ,fmtparptr [i ]-> pointflag );
459+ fmtparptr [i ]-> precision ,fmtparptr [i ]-> pointflag ,
460+ end );
462461break ;
463462case FMTCHAR :
464- dopr_outch (fmtparptr [i ]-> charvalue );
463+ dopr_outch (fmtparptr [i ]-> charvalue , end );
465464break ;
466465}
467466format = fmtpar [i ].fmtend ;
468467gotonochar ;
469468}
470469}
471- dopr_outch (ch );
470+ dopr_outch (ch , end );
472471nochar :
473472/* nothing */
474473;/* semicolon required because a goto has to be attached to a statement */
@@ -477,7 +476,7 @@ dopr(char *buffer, const char *format, va_list args)
477476}
478477
479478static void
480- fmtstr (char * value ,int ljust ,int len ,int zpad ,int maxwidth )
479+ fmtstr (char * value ,int ljust ,int len ,int zpad ,int maxwidth , char * end )
481480{
482481int padlen ,
483482strlen ;/* amount to pad */
@@ -494,19 +493,19 @@ fmtstr(char *value, int ljust, int len, int zpad, int maxwidth)
494493padlen = - padlen ;
495494while (padlen > 0 )
496495{
497- dopr_outch (' ' );
496+ dopr_outch (' ' , end );
498497-- padlen ;
499498}
500- dostr (value ,maxwidth );
499+ dostr (value ,maxwidth , end );
501500while (padlen < 0 )
502501{
503- dopr_outch (' ' );
502+ dopr_outch (' ' , end );
504503++ padlen ;
505504}
506505}
507506
508507static void
509- fmtnum (long_long value ,int base ,int dosign ,int ljust ,int len ,int zpad )
508+ fmtnum (long_long value ,int base ,int dosign ,int ljust ,int len ,int zpad , char * end )
510509{
511510int signvalue = 0 ;
512511ulong_long uvalue ;
@@ -561,34 +560,34 @@ fmtnum(long_long value, int base, int dosign, int ljust, int len, int zpad)
561560{
562561if (signvalue )
563562{
564- dopr_outch (signvalue );
563+ dopr_outch (signvalue , end );
565564-- padlen ;
566565signvalue = 0 ;
567566}
568567while (padlen > 0 )
569568{
570- dopr_outch (zpad );
569+ dopr_outch (zpad , end );
571570-- padlen ;
572571}
573572}
574573while (padlen > 0 )
575574{
576- dopr_outch (' ' );
575+ dopr_outch (' ' , end );
577576-- padlen ;
578577}
579578if (signvalue )
580- dopr_outch (signvalue );
579+ dopr_outch (signvalue , end );
581580while (place > 0 )
582- dopr_outch (convert [-- place ]);
581+ dopr_outch (convert [-- place ], end );
583582while (padlen < 0 )
584583{
585- dopr_outch (' ' );
584+ dopr_outch (' ' , end );
586585++ padlen ;
587586}
588587}
589588
590589static void
591- fmtfloat (double value ,char type ,int ljust ,int len ,int precision ,int pointflag )
590+ fmtfloat (double value ,char type ,int ljust ,int len ,int precision ,int pointflag , char * end )
592591{
593592char fmt [32 ];
594593char convert [512 ];
@@ -615,34 +614,34 @@ fmtfloat(double value, char type, int ljust, int len, int precision, int pointfl
615614
616615while (padlen > 0 )
617616{
618- dopr_outch (' ' );
617+ dopr_outch (' ' , end );
619618-- padlen ;
620619}
621- dostr (convert ,0 );
620+ dostr (convert ,0 , end );
622621while (padlen < 0 )
623622{
624- dopr_outch (' ' );
623+ dopr_outch (' ' , end );
625624++ padlen ;
626625}
627626}
628627
629628static void
630- dostr (char * str ,int cut )
629+ dostr (char * str ,int cut , char * end )
631630{
632631if (cut )
633632{
634633while (* str && cut -- > 0 )
635- dopr_outch (* str ++ );
634+ dopr_outch (* str ++ , end );
636635}
637636else
638637{
639638while (* str )
640- dopr_outch (* str ++ );
639+ dopr_outch (* str ++ , end );
641640}
642641}
643642
644643static void
645- dopr_outch (int c )
644+ dopr_outch (int c , char * end )
646645{
647646#ifdef NOT_USED
648647if (iscntrl ((unsignedchar )c )&& c != '\n' && c != '\t' )
@@ -654,6 +653,4 @@ dopr_outch(int c)
654653#endif
655654if (end == 0 || output < end )
656655* output ++ = c ;
657- else
658- SnprfOverflow ++ ;
659656}