Skip to content

Commit 343a9a2

Browse files
committed
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.
1 parent 4835df3 commit 343a9a2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/backend/utils/adt/selfuncs.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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
31533157
xfrmlen = 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
31553168
xfrmstr = (char *) palloc(xfrmlen + 1);
31563169
xfrmlen2 = strxfrm(xfrmstr, val, xfrmlen + 1);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy