aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2007-05-05 17:05:55 +0000
committerMagnus Hagander <magnus@hagander.net>2007-05-05 17:05:55 +0000
commitff5ff47b5dd6d48aa5f0dd27007e1a17f9566bb5 (patch)
tree42e73169c5b4f576ab207be9319a11424f6149b2 /src
parent61f9c3a54d39f32940d8d9e41b62283f5a16c37d (diff)
downloadpostgresql-ff5ff47b5dd6d48aa5f0dd27007e1a17f9566bb5.tar.gz
postgresql-ff5ff47b5dd6d48aa5f0dd27007e1a17f9566bb5.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/selfuncs.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index b65959047c2..0fcfdcbf322 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.214.2.4 2007/01/28 02:53:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.214.2.5 2007/05/05 17:05:55 mha Exp $
*
*-------------------------------------------------------------------------
*/
@@ -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 */
@@ -3141,6 +3145,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);
Assert(xfrmlen2 <= xfrmlen);