Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae3ff7a

Browse files
committed
Fix (I think) broken usage of MultiByteToWideChar. I had missed the
subtlety that this function only returns a null terminator if it'sfed input that includes one; which, in the usage here, it's not.This probably fixes bugs reported by Thomas Haegi.
1 parent0f20e7a commitae3ff7a

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

‎src/backend/tsearch/ts_locale.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/ts_locale.c,v 1.4 2007/11/15 21:14:38 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/ts_locale.c,v 1.5 2007/11/24 21:20:07 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -23,7 +23,7 @@
2323
* wchar2char --- convert wide characters to multibyte format
2424
*
2525
* This has the same API as the standard wcstombs() function; in particular,
26-
* tolen is the maximum number of bytes to store at *to, and *fromshould be
26+
* tolen is the maximum number of bytes to store at *to, and *frommust be
2727
* zero-terminated. The output will be zero-terminated iff there is room.
2828
*/
2929
size_t
@@ -73,21 +73,28 @@ char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen)
7373
{
7474
intr;
7575

76-
r=MultiByteToWideChar(CP_UTF8,0,from,fromlen,to,tolen);
77-
78-
if (r <=0)
76+
/* stupid Microsloth API does not work for zero-length input */
77+
if (fromlen==0)
78+
r=0;
79+
else
7980
{
80-
pg_verifymbstr(from,fromlen, false);
81-
ereport(ERROR,
82-
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
83-
errmsg("invalid multibyte character for locale"),
84-
errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding.")));
81+
r=MultiByteToWideChar(CP_UTF8,0,from,fromlen,to,tolen-1);
82+
83+
if (r <=0)
84+
{
85+
/* see notes in oracle_compat.c about error reporting */
86+
pg_verifymbstr(from,fromlen, false);
87+
ereport(ERROR,
88+
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
89+
errmsg("invalid multibyte character for locale"),
90+
errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding.")));
91+
}
8592
}
8693

87-
Assert(r <=tolen);
94+
Assert(r<tolen);
95+
to[r]=0;
8896

89-
/* Microsoft counts the zero terminator in the result */
90-
returnr-1;
97+
returnr;
9198
}
9299
#endif/* WIN32 */
93100

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp