Patch for str_numth() in PG 7.4
Hello,
even if 7.4 is almost at the end of it's lifetime i found a bug/problem
on a fairly new laptop (not surprising: during upgrade tests). All
timestamp regression tests failed, only "th" was emitted.
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.
Since this patch is easy enough (replacing one line with three
lines of code), does not seem to break existing code and removes at
least one bug i ask to include this patch into the next 7.4 release (i
assume there will be at least one release if 7.4 reaches eol).
Thanks & kind regards
--
Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors
Attachments:
linebreaks_for_l_plus_2008-12-21.patchtext/x-patch; name=linebreaks_for_l_plus_2008-12-21.patchDownload
*** src/bin/psql/describe.c 2008-12-21 13:19:40.000000000 +0100
--- src/bin/psql/describe.c.orig 2008-12-21 02:16:31.000000000 +0100
***************
*** 464,476 ****
" d.datctype as \"%s\",\n",
gettext_noop("Collation"),
gettext_noop("Ctype"));
! if (pset.sversion >= 80100)
! appendPQExpBuffer(&buf,
! " pg_catalog.array_to_string(d.datacl, E'\\n') as \"%s\"",
! gettext_noop("Access Privileges"));
! else
! appendPQExpBuffer(&buf,
! " pg_catalog.array_to_string(d.datacl, '\\n') as \"%s\"",
gettext_noop("Access Privileges"));
if (verbose && pset.sversion >= 80200)
appendPQExpBuffer(&buf,
--- 464,471 ----
" d.datctype as \"%s\",\n",
gettext_noop("Collation"),
gettext_noop("Ctype"));
! appendPQExpBuffer(&buf,
! " d.datacl as \"%s\"",
gettext_noop("Access Privileges"));
if (verbose && pset.sversion >= 80200)
appendPQExpBuffer(&buf,
Andreas 'ads' Scherbaum <adsmail@wars-nicht.de> writes:
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.
I think you attached the wrong patch.
*** src/bin/psql/describe.c 2008-12-21 13:19:40.000000000 +0100 --- src/bin/psql/describe.c.orig 2008-12-21 02:16:31.000000000 +0100 *************** *** 464,476 **** " d.datctype as \"%s\",\n", gettext_noop("Collation"), gettext_noop("Ctype")); ! if (pset.sversion >= 80100) ! appendPQExpBuffer(&buf, ! " pg_catalog.array_to_string(d.datacl, E'\\n') as \"%s\"", ! gettext_noop("Access Privileges")); ! else ! appendPQExpBuffer(&buf, ! " pg_catalog.array_to_string(d.datacl, '\\n') as \"%s\"", gettext_noop("Access Privileges")); if (verbose && pset.sversion >= 80200) appendPQExpBuffer(&buf, --- 464,471 ---- " d.datctype as \"%s\",\n", gettext_noop("Collation"), gettext_noop("Ctype")); ! appendPQExpBuffer(&buf, ! " d.datacl as \"%s\"", gettext_noop("Access Privileges")); if (verbose && pset.sversion >= 80200) appendPQExpBuffer(&buf,
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's RemoteDBA services!
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 ;-)
Kind regards
--
Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors
Attachments:
formatting-str_numth-7.4.patchtext/x-patch; name=formatting-str_numth-7.4.patchDownload
diff -rc postgresql-7.4.23.orig/src/backend/utils/adt/formatting.c postgresql-7.4.23.patch/src/backend/utils/adt/formatting.c
*** postgresql-7.4.23.orig/src/backend/utils/adt/formatting.c 2007-06-29 03:52:14.000000000 +0200
--- postgresql-7.4.23.patch/src/backend/utils/adt/formatting.c 2009-01-12 22:39:47.000000000 +0100
***************
*** 1444,1450 ****
static char *
str_numth(char *dest, char *num, int type)
{
! sprintf(dest, "%s%s", num, get_th(num, type));
return dest;
}
--- 1444,1452 ----
static char *
str_numth(char *dest, char *num, int type)
{
! if (dest != num)
! strcpy(dest, num);
! strcat(dest, get_th(num, type));
return dest;
}
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
Attachments:
patchtext/plain; charset=us-asciiDownload
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
Alvaro Herrera <alvherre@commandprompt.com> writes:
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.
I dunno why I didn't back-patch that; feel free to do so. Better do the
whole thing, because anything that chokes on str_numth's abuse of
sprintf is not going to like those other cases either.
regards, tom lane
Tom Lane wrote:
Alvaro Herrera <alvherre@commandprompt.com> writes:
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.I dunno why I didn't back-patch that; feel free to do so. Better do the
whole thing, because anything that chokes on str_numth's abuse of
sprintf is not going to like those other cases either.
The other cases were already handled, so Andreas' initial patch was
enough -- applied.
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support