From 32032d42b51bf673bdc17b2248a6a32b4de30676 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Mon, 2 Mar 2009 15:10:09 +0000 Subject: Fix usage of char2wchar/wchar2char. Changes: - pg_wchar and wchar_t could have different size, so char2wchar doesn't call pg_mb2wchar_with_len to prevent out-of-bound memory bug - make char2wchar/wchar2char symmetric, now they should not be called with C-locale because mbstowcs/wcstombs oftenly doesn't work correct with C-locale. - Text parser uses pg_mb2wchar_with_len directly in case of C-locale and multibyte encoding Per bug report by Hiroshi Inoue and following discussion. Backpatch up to 8.2 when multybyte support was implemented in tsearch. --- src/backend/utils/mb/mbutils.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/backend/utils/mb/mbutils.c') diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index c3cf7f5db69..f5ba80d101d 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -4,7 +4,7 @@ * (currently mule internal code (mic) is used) * Tatsuo Ishii * - * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.78 2009/01/22 10:09:48 mha Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.79 2009/03/02 15:10:09 teodor Exp $ */ #include "postgres.h" @@ -601,7 +601,10 @@ wchar2char(char *to, const wchar_t *from, size_t tolen) } else #endif /* WIN32 */ + { + Assert( !lc_ctype_is_c() ); result = wcstombs(to, from, tolen); + } return result; } @@ -647,22 +650,12 @@ char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen) else #endif /* WIN32 */ { - if (lc_ctype_is_c()) - { - /* - * pg_mb2wchar_with_len always adds trailing '\0', so 'to' should be - * allocated with sufficient space - */ - result = pg_mb2wchar_with_len(from, (pg_wchar *) to, fromlen); - } - else - { - /* mbstowcs requires ending '\0' */ - char *str = pnstrdup(from, fromlen); + /* mbstowcs requires ending '\0' */ + char *str = pnstrdup(from, fromlen); - result = mbstowcs(to, str, tolen); - pfree(str); - } + Assert( !lc_ctype_is_c() ); + result = mbstowcs(to, str, tolen); + pfree(str); } if (result == -1) -- cgit v1.2.3