Commit 59d9a370 authored by Tom Lane's avatar Tom Lane

Work around buggy strxfrm() present in some Solaris releases.

parent 0c172909
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.139 2003/05/28 16:03:59 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.140 2003/07/17 20:52:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2651,9 +2651,6 @@ static unsigned char * ...@@ -2651,9 +2651,6 @@ static unsigned char *
convert_string_datum(Datum value, Oid typid) convert_string_datum(Datum value, Oid typid)
{ {
char *val; char *val;
char *xfrmstr;
size_t xfrmsize;
size_t xfrmlen;
switch (typid) switch (typid)
{ {
...@@ -2693,17 +2690,21 @@ convert_string_datum(Datum value, Oid typid) ...@@ -2693,17 +2690,21 @@ convert_string_datum(Datum value, Oid typid)
if (!lc_collate_is_c()) if (!lc_collate_is_c())
{ {
/* Guess that transformed string is not much bigger than original */ char *xfrmstr;
xfrmsize = strlen(val) + 32; /* arbitrary pad value here... */ size_t xfrmlen;
xfrmstr = (char *) palloc(xfrmsize); size_t xfrmlen2;
xfrmlen = strxfrm(xfrmstr, val, xfrmsize);
if (xfrmlen >= xfrmsize) /*
{ * Note: originally we guessed at a suitable output buffer size,
/* Oops, didn't make it */ * and only needed to call strxfrm twice if our guess was too small.
pfree(xfrmstr); * However, it seems that some versions of Solaris have buggy
* strxfrm that can write past the specified buffer length in that
* scenario. So, do it the dumb way for portability.
*/
xfrmlen = strxfrm(NULL, val, 0);
xfrmstr = (char *) palloc(xfrmlen + 1); xfrmstr = (char *) palloc(xfrmlen + 1);
xfrmlen = strxfrm(xfrmstr, val, xfrmlen + 1); xfrmlen2 = strxfrm(xfrmstr, val, xfrmlen + 1);
} Assert(xfrmlen2 == xfrmlen);
pfree(val); pfree(val);
val = xfrmstr; val = xfrmstr;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment