1515 *
1616 *
1717 * IDENTIFICATION
18- * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.233 2007/04/21 21:01:45 tgl Exp $
18+ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.234 2007/05/05 17:05:48 mha Exp $
1919 *
2020 *-------------------------------------------------------------------------
2121 */
@@ -3137,6 +3137,10 @@ convert_string_datum(Datum value, Oid typid)
31373137 * from the second call than the first; thus the Assert must be <= not
31383138 * == as you'd expect. Can't any of these people program their way
31393139 * out of a paper bag?
3140+ *
3141+ * XXX: strxfrm doesn't support UTF-8 encoding on Win32, it can return
3142+ * bogus data or set an error. This is not really a problem unless it
3143+ * crashes since it will only give an estimation error and nothing fatal.
31403144 */
31413145#if _MSC_VER == 1400 /* VS.Net 2005 */
31423146
@@ -3151,6 +3155,15 @@ convert_string_datum(Datum value, Oid typid)
31513155}
31523156#else
31533157xfrmlen = strxfrm (NULL ,val ,0 );
3158+ #endif
3159+ #ifdef WIN32
3160+ /*
3161+ * On Windows, strxfrm returns INT_MAX when an error occurs. Instead of
3162+ * trying to allocate this much memory (and fail), just return the
3163+ * original string unmodified as if we were in the C locale.
3164+ */
3165+ if (xfrmlen == INT_MAX )
3166+ return val ;
31543167#endif
31553168xfrmstr = (char * )palloc (xfrmlen + 1 );
31563169xfrmlen2 = strxfrm (xfrmstr ,val ,xfrmlen + 1 );