diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2009-03-02 15:10:09 +0000 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2009-03-02 15:10:09 +0000 |
commit | 32032d42b51bf673bdc17b2248a6a32b4de30676 (patch) | |
tree | 58cbe8df3ae9f25fa8eab5274f9f38812998316f /src/backend/utils/mb | |
parent | 876b37d50ab70cae8cde5337ec27cec649ef1677 (diff) | |
download | postgresql-32032d42b51bf673bdc17b2248a6a32b4de30676.tar.gz |
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 <inoue@tpf.co.jp> and
following discussion.
Backpatch up to 8.2 when multybyte support was implemented in tsearch.
Diffstat (limited to 'src/backend/utils/mb')
-rw-r--r-- | src/backend/utils/mb/mbutils.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index c3cf7f5db6..f5ba80d101 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) |