Andreas 'ads' Scherbaum wrote: > > Hello all, > > On Mon, 12 Jan 2009 22:55:32 +0100 Andreas 'ads' Scherbaum wrote: > > > I tracked the problem done to the function str_numth() in > > src/backend/utils/adt/formatting.c. The fix (attached) is easy: i > > stole the function code from the latest 8.0 version which looks fare > > more sane in handling the string pointers. > > Now with the correct patch attached, thanks to anyone who pointed this > out ;-)
This was fixed on 1.84 of formatting.c for 8.0 (but not backpatched for no apparent reason), which also changed some other stuff in that file. The complete patch is attached. revision 1.84 date: 2005-01-12 22:40:13 -0300; author: tgl; state: Exp; lines: +9 -7; branches: 1.84.4; Remove unportable assumption that it's okay to use the target buffer of an sprintf() as a source string. Demonstrably does not work with recent gcc and/or glibc on some platforms. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Index: src/backend/utils/adt/formatting.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/adt/formatting.c,v retrieving revision 1.83 retrieving revision 1.84 diff -c -p -r1.83 -r1.84 *** src/backend/utils/adt/formatting.c 1 Jan 2005 05:43:07 -0000 1.83 --- src/backend/utils/adt/formatting.c 13 Jan 2005 01:40:13 -0000 1.84 *************** *** 1,7 **** /* ----------------------------------------------------------------------- * formatting.c * ! * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.83 2005-01-01 05:43:07 momjian Exp $ * * * Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group --- 1,7 ---- /* ----------------------------------------------------------------------- * formatting.c * ! * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.84 2005-01-13 01:40:13 tgl Exp $ * * * Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group *************** get_th(char *num, int type) *** 1462,1468 **** static char * str_numth(char *dest, char *num, int type) { ! sprintf(dest, "%s%s", num, get_th(num, type)); return dest; } --- 1462,1470 ---- static char * str_numth(char *dest, char *num, int type) { ! if (dest != num) ! strcpy(dest, num); ! strcat(dest, get_th(num, type)); return dest; } *************** static int *** 2057,2062 **** --- 2059,2065 ---- dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) { char buff[DCH_CACHE_SIZE], + workbuff[32], *p_inout; int i, len; *************** dch_date(int arg, char *inout, int suf, *** 2117,2123 **** switch (arg) { - case DCH_A_D: case DCH_B_C: if (flag == TO_CHAR) --- 2120,2125 ---- *************** dch_date(int arg, char *inout, int suf, *** 2179,2186 **** } break; case DCH_MONTH: ! strcpy(inout, months_full[tm->tm_mon - 1]); ! sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, str_toupper(inout)); if (S_FM(suf)) return strlen(p_inout) - 1; else --- 2181,2188 ---- } break; case DCH_MONTH: ! strcpy(workbuff, months_full[tm->tm_mon - 1]); ! sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, str_toupper(workbuff)); if (S_FM(suf)) return strlen(p_inout) - 1; else *************** dch_date(int arg, char *inout, int suf, *** 2242,2249 **** } break; case DCH_DAY: ! strcpy(inout, days[tm->tm_wday]); ! sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, str_toupper(inout)); if (S_FM(suf)) return strlen(p_inout) - 1; else --- 2244,2251 ---- } break; case DCH_DAY: ! strcpy(workbuff, days[tm->tm_wday]); ! sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, str_toupper(workbuff)); if (S_FM(suf)) return strlen(p_inout) - 1; else
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers