From: Magnus Hagander Date: Sat, 5 May 2007 17:05:55 +0000 (+0000) Subject: Check return code from strxfrm on Windows since it has a X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=eb065e90f4d4fff52318076cdc2e6f24e4d313c9;p=users%2Fbernd%2Fpostgres.git Check return code from strxfrm on Windows since it has a non-standard way of indicating errors, so we don't try to allocate INT_MAX bytes to store a result in. --- diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 94cb8ab6f1..e53818790a 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -3126,6 +3126,10 @@ convert_string_datum(Datum value, Oid typid) * from the second call than the first; thus the Assert must be <= not * == as you'd expect. Can't any of these people program their way * out of a paper bag? + * + * XXX: strxfrm doesn't support UTF-8 encoding on Win32, it can return + * bogus data or set an error. This is not really a problem unless it + * crashes since it will only give an estimation error and nothing fatal. */ #if _MSC_VER == 1400 /* VS.Net 2005 */ @@ -3140,6 +3144,15 @@ convert_string_datum(Datum value, Oid typid) } #else xfrmlen = strxfrm(NULL, val, 0); +#endif +#ifdef WIN32 + /* + * On Windows, strxfrm returns INT_MAX when an error occurs. Instead of + * trying to allocate this much memory (and fail), just return the + * original string unmodified as if we were in the C locale. + */ + if (xfrmlen == INT_MAX) + return val; #endif xfrmstr = (char *) palloc(xfrmlen + 1); xfrmlen2 = strxfrm(xfrmstr, val, xfrmlen + 1);