Index: src/port/snprintf.c =================================================================== RCS file: /cvsroot/pgsql/src/port/snprintf.c,v retrieving revision 1.11 diff -c -c -r1.11 snprintf.c *** src/port/snprintf.c 2 Mar 2005 03:21:52 -0000 1.11 --- src/port/snprintf.c 2 Mar 2005 05:17:01 -0000 *************** *** 32,49 **** * SUCH DAMAGE. */ ! /* might be in either frontend or backend */ #include "postgres_fe.h" #ifndef WIN32 #include #endif #include - #ifndef NL_ARGMAX - #define NL_ARGMAX 4096 - #endif - /* ** SNPRINTF, VSNPRINT -- counted versions of printf ** --- 32,48 ---- * SUCH DAMAGE. */ ! #ifndef FRONTEND ! #include "postgres.h" ! #else #include "postgres_fe.h" + #endif #ifndef WIN32 #include #endif #include /* ** SNPRINTF, VSNPRINT -- counted versions of printf ** *************** *** 157,167 **** int realpos = 0; int position; char *output; ! /* In thread mode this structure is too large. */ ! #ifndef ENABLE_THREAD_SAFETY ! static ! #endif ! struct{ const char* fmtbegin; const char* fmtend; void* value; --- 156,164 ---- int realpos = 0; int position; char *output; ! int percents = 1; ! const char *p; ! struct fmtpar { const char* fmtbegin; const char* fmtend; void* value; *************** *** 179,188 **** int pointflag; char func; int realpos; ! } fmtpar[NL_ARGMAX+1], *fmtparptr[NL_ARGMAX+1]; ! format_save = format; output = buffer; while ((ch = *format++)) { --- 176,205 ---- int pointflag; char func; int realpos; ! } *fmtpar, **fmtparptr; + /* Create enough structures to hold all arguments */ + for (p = format; *p != '\0'; p++) + if (*p == '%') /* counts %% as two, so overcounts */ + percents++; + #ifndef FRONTEND + fmtpar = pgport_palloc(sizeof(struct fmtpar) * percents); + fmtparptr = pgport_palloc(sizeof(struct fmtpar *) * percents); + #else + if ((fmtpar = malloc(sizeof(struct fmtpar) * percents)) == NULL) + { + fprintf(stderr, _("out of memory\n")); + exit(1); + } + if ((fmtparptr = malloc(sizeof(struct fmtpar *) * percents)) == NULL) + { + fprintf(stderr, _("out of memory\n")); + exit(1); + } + #endif + format_save = format; + output = buffer; while ((ch = *format++)) { *************** *** 418,426 **** performpr: /* shuffle pointers */ for(i = 1; i < fmtpos; i++) - { fmtparptr[i] = &fmtpar[fmtpar[i].realpos]; - } output = buffer; format = format_save; while ((ch = *format++)) --- 435,441 ---- *************** *** 465,470 **** --- 480,493 ---- ; /* semicolon required because a goto has to be attached to a statement */ } *output = '\0'; + + #ifndef FRONTEND + pgport_pfree(fmtpar); + pgport_pfree(fmtparptr); + #else + free(fmtpar); + free(fmtparptr); + #endif } static void