Skip to content

Commit 804f6b8

Browse files
committed
Fix long standing Asian multibyte charsets bug.
See: Subject: [HACKERS] bugs with certain Asian multibyte charsets From: Tatsuo Ishii <ishii@sraoss.co.jp> To: pgsql-hackers@postgresql.org Date: Sat, 24 Dec 2005 18:25:33 +0900 (JST) for more details/
1 parent 7d732f0 commit 804f6b8

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/backend/utils/mb/wchar.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* conversion functions between pg_wchar and multibyte streams.
33
* Tatsuo Ishii
4-
* $PostgreSQL: pgsql/src/backend/utils/mb/wchar.c,v 1.47 2005/10/29 00:31:52 petere Exp $
4+
* $PostgreSQL: pgsql/src/backend/utils/mb/wchar.c,v 1.48 2005/12/24 09:35:36 ishii Exp $
55
*
66
* WIN1250 client encoding updated by Pavel Behal
77
*
@@ -58,34 +58,33 @@ pg_ascii_dsplen(const unsigned char *s)
5858
/*
5959
* EUC
6060
*/
61-
6261
static int pg_euc2wchar_with_len
6362
(const unsigned char *from, pg_wchar *to, int len)
6463
{
6564
int cnt = 0;
6665

6766
while (len > 0 && *from)
6867
{
69-
if (*from == SS2 && len >= 2)
68+
if (*from == SS2 && len >= 2) /* JIS X 0201 (so called "1 byte KANA") */
7069
{
7170
from++;
72-
*to = 0xff & *from++;
71+
*to = (SS2 << 8) | *from++;
7372
len -= 2;
7473
}
75-
else if (*from == SS3 && len >= 3)
74+
else if (*from == SS3 && len >= 3) /* JIS X 0212 KANJI */
7675
{
7776
from++;
78-
*to = *from++ << 8;
79-
*to |= 0x3f & *from++;
77+
*to = (SS3 << 16) | (*from++ << 8);
78+
*to |= *from++;
8079
len -= 3;
8180
}
82-
else if ((*from & 0x80) && len >= 2)
81+
else if ((*from & 0x80) && len >= 2) /* JIS X 0208 KANJI */
8382
{
8483
*to = *from++ << 8;
8584
*to |= *from++;
8685
len -= 2;
8786
}
88-
else
87+
else /* must be ASCII */
8988
{
9089
*to = *from++;
9190
len--;
@@ -183,6 +182,7 @@ pg_euckr_dsplen(const unsigned char *s)
183182

184183
/*
185184
* EUC_CN
185+
*
186186
*/
187187
static int pg_euccn2wchar_with_len
188188
(const unsigned char *from, pg_wchar *to, int len)
@@ -191,21 +191,21 @@ static int pg_euccn2wchar_with_len
191191

192192
while (len > 0 && *from)
193193
{
194-
if (*from == SS2 && len >= 3)
194+
if (*from == SS2 && len >= 3) /* code set 2 (unused?) */
195195
{
196196
from++;
197-
*to = 0x3f00 & (*from++ << 8);
198-
*to = *from++;
197+
*to = (SS2 << 16) | (*from++ << 8);
198+
*to |= *from++;
199199
len -= 3;
200200
}
201-
else if (*from == SS3 && len >= 3)
201+
else if (*from == SS3 && len >= 3) /* code set 3 (unsed ?) */
202202
{
203203
from++;
204-
*to = *from++ << 8;
205-
*to |= 0x3f & *from++;
204+
*to = (SS3 << 16) | (*from++ << 8);
205+
*to |= *from++;
206206
len -= 3;
207207
}
208-
else if ((*from & 0x80) && len >= 2)
208+
else if ((*from & 0x80) && len >= 2) /* code set 1 */
209209
{
210210
*to = *from++ << 8;
211211
*to |= *from++;
@@ -249,6 +249,7 @@ pg_euccn_dsplen(const unsigned char *s)
249249

250250
/*
251251
* EUC_TW
252+
*
252253
*/
253254
static int pg_euctw2wchar_with_len
254255
(const unsigned char *from, pg_wchar *to, int len)
@@ -257,22 +258,22 @@ static int pg_euctw2wchar_with_len
257258

258259
while (len > 0 && *from)
259260
{
260-
if (*from == SS2 && len >= 4)
261+
if (*from == SS2 && len >= 4) /* code set 2 */
261262
{
262263
from++;
263-
*to = *from++ << 16;
264+
*to = (SS2 << 24) | (*from++ << 16) ;
264265
*to |= *from++ << 8;
265266
*to |= *from++;
266267
len -= 4;
267268
}
268-
else if (*from == SS3 && len >= 3)
269+
else if (*from == SS3 && len >= 3) /* code set 3 (unused?) */
269270
{
270271
from++;
271-
*to = *from++ << 8;
272-
*to |= 0x3f & *from++;
272+
*to = (SS3 << 16) | (*from++ << 8);
273+
*to |= *from++;
273274
len -= 3;
274275
}
275-
else if ((*from & 0x80) && len >= 2)
276+
else if ((*from & 0x80) && len >= 2) /* code set 2 */
276277
{
277278
*to = *from++ << 8;
278279
*to |= *from++;

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