|
7 | 7 | * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
10 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.80 2008/10/29 08:04:53 petere Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.81 2008/11/10 18:02:20 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -1405,7 +1405,11 @@ sqlchar_to_unicode(char *s)
|
1405 | 1405 | GetDatabaseEncoding(),
|
1406 | 1406 | PG_UTF8);
|
1407 | 1407 |
|
1408 |
| - pg_encoding_mb2wchar_with_len(PG_UTF8, utf8string, ret, pg_mblen(s)); |
| 1408 | + pg_encoding_mb2wchar_with_len(PG_UTF8, utf8string, ret, |
| 1409 | + pg_encoding_mblen(PG_UTF8, utf8string)); |
| 1410 | + |
| 1411 | + if (utf8string != s) |
| 1412 | + pfree(utf8string); |
1409 | 1413 |
|
1410 | 1414 | return ret[0];
|
1411 | 1415 | }
|
@@ -1495,14 +1499,21 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped,
|
1495 | 1499 | static char *
|
1496 | 1500 | unicode_to_sqlchar(pg_wchar c)
|
1497 | 1501 | {
|
1498 |
| - static unsigned char utf8string[5]; /* need trailing zero */ |
| 1502 | + unsigned char utf8string[5]; /* need room for trailing zero */ |
| 1503 | + char *result; |
1499 | 1504 |
|
| 1505 | + memset(utf8string, 0, sizeof(utf8string)); |
1500 | 1506 | unicode_to_utf8(c, utf8string);
|
1501 | 1507 |
|
1502 |
| - return (char *) pg_do_encoding_conversion(utf8string, |
1503 |
| - pg_mblen((char *) utf8string), |
1504 |
| - PG_UTF8, |
1505 |
| - GetDatabaseEncoding()); |
| 1508 | + result = (char *) pg_do_encoding_conversion(utf8string, |
| 1509 | + pg_encoding_mblen(PG_UTF8, |
| 1510 | + (char *) utf8string), |
| 1511 | + PG_UTF8, |
| 1512 | + GetDatabaseEncoding()); |
| 1513 | + /* if pg_do_encoding_conversion didn't strdup, we must */ |
| 1514 | + if (result == (char *) utf8string) |
| 1515 | + result = pstrdup(result); |
| 1516 | + return result; |
1506 | 1517 | }
|
1507 | 1518 |
|
1508 | 1519 |
|
|
0 commit comments