Skip to content

Commit 3c6cd8a

Browse files
committed
Fixes motivated by snake and spoonbill pgbuildfarm members
1 parent 725ace4 commit 3c6cd8a

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

contrib/tsearch2/ts_locale.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,44 @@
88
#if defined(TS_USE_WIDE) && defined(WIN32)
99

1010
size_t
11-
wchar2char( const char *to, const wchar_t *from, size_t len ) {
11+
wchar2char( char *to, const wchar_t *from, size_t len ) {
1212
if (GetDatabaseEncoding() == PG_UTF8) {
13-
int r;
13+
int r, nbytes;
1414

1515
if (len==0)
1616
return 0;
1717

18+
/* in any case, *to should be allocated with enough space */
19+
nbytes = WideCharToMultiByte(CP_UTF8, 0, from, len, NULL, 0, NULL, NULL);
20+
if ( nbytes==0 )
21+
ereport(ERROR,
22+
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
23+
errmsg("UTF-16 to UTF-8 translation failed: %lu",
24+
GetLastError())));
25+
1826
r = WideCharToMultiByte(CP_UTF8, 0, from, len, to, nbytes,
1927
NULL, NULL);
2028

21-
2229
if ( r==0 )
2330
ereport(ERROR,
2431
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
2532
errmsg("UTF-16 to UTF-8 translation failed: %lu",
2633
GetLastError())));
27-
2834
return r;
2935
}
3036

3137
return wcstombs(to, from, len);
3238
}
3339

3440
size_t
35-
char2wchar( const wchar_t *to, const char *from, size_t len ) {
41+
char2wchar( wchar_t *to, const char *from, size_t len ) {
3642
if (GetDatabaseEncoding() == PG_UTF8) {
3743
int r;
3844

3945
if (len==0)
4046
return 0;
4147

42-
r = MultiByteToWideChar(CP_UTF8, 0, from, len,
43-
to, len);
48+
r = MultiByteToWideChar(CP_UTF8, 0, from, len, to, len);
4449

4550
if (!r) {
4651
pg_verifymbstr(from, len, false);
@@ -50,7 +55,7 @@ char2wchar( const wchar_t *to, const char *from, size_t len ) {
5055
errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding.")));
5156
}
5257

53-
Assert(r <= nbytes);
58+
Assert( r <= len );
5459

5560
return r;
5661
}

contrib/tsearch2/ts_locale.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
#ifdef WIN32
2424

25-
size_t wchar2char( const char *to, const wchar_t *from, size_t len );
26-
size_t char2wchar( const wchar_t *to, const char *from, size_t len );
25+
size_t wchar2char( char *to, const wchar_t *from, size_t len );
26+
size_t char2wchar( wchar_t *to, const char *from, size_t len );
2727

2828
#else /* WIN32 */
2929

contrib/tsearch2/wordparser/parser.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ TParserClose( TParser* prs ) {
7979
static int \
8080
p_is##type(TParser *prs) { \
8181
Assert( prs->state ); \
82-
return ( ( prs->usewide ) ? isw##type( (wint_t)*( prs->wstr + prs->state->poschar ) ) : \
82+
return ( ( prs->usewide ) ? isw##type( (wint_t)*( prs->wstr + prs->state->poschar ) ) : \
8383
is##type( (unsigned char)*( prs->str + prs->state->posbyte ) ) ); \
8484
} \
8585
\
@@ -104,7 +104,7 @@ p_iseq(TParser *prs, char c) {
104104
static int \
105105
p_is##type(TParser *prs) { \
106106
Assert( prs->state ); \
107-
return is##type( (unsigned char)*( prs->str + prs->state->posbyte ) ) ); \
107+
return is##type( (unsigned char)*( prs->str + prs->state->posbyte ) ); \
108108
} \
109109
\
110110
static int \
@@ -116,7 +116,7 @@ p_isnot##type(TParser *prs) { \
116116
static int
117117
p_iseq(TParser *prs, char c) {
118118
Assert( prs->state );
119-
return ( *( prs->str + prs->state->posbyte ) == c ) ) ? 1 : 0;
119+
return ( *( prs->str + prs->state->posbyte ) == c ) ? 1 : 0;
120120
}
121121

122122
#endif /* TS_USE_WIDE */

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