Skip to content

Commit d81fd94

Browse files
committed
Fix ILIKE bug (only in multi-byte case)
1 parent e8caade commit d81fd94

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/backend/utils/adt/like.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.42 2000/09/15 18:45:26 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.43 2000/12/11 05:00:18 ishii Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -63,35 +63,34 @@ static int wchareq(unsigned char *p1, unsigned char *p2)
6363
* If they match, returns 1 otherwise returns 0.
6464
*--------------------
6565
*/
66-
#define UCHARMAX 0xff
66+
#define CHARMAX 0x80
6767

6868
static int iwchareq(unsigned char *p1, unsigned char *p2)
6969
{
70-
int c1, c2;
70+
int c1[2], c2[2];
7171
int l;
7272

73-
/* short cut. if *p1 and *p2 is lower than UCHARMAX, then
74-
we assume they are ASCII */
75-
if (*p1 < UCHARMAX && *p2 < UCHARMAX)
73+
/* short cut. if *p1 and *p2 is lower than CHARMAX, then
74+
we could assume they are ASCII */
75+
if (*p1 < CHARMAX && *p2 < CHARMAX)
7676
return(tolower(*p1) == tolower(*p2));
7777

78-
if (*p1 < UCHARMAX)
79-
c1 = tolower(*p1);
80-
else
81-
{
82-
l = pg_mblen(p1);
83-
(void)pg_mb2wchar_with_len(p1, (pg_wchar *)&c1, l);
84-
c1 = tolower(c1);
85-
}
86-
if (*p2 < UCHARMAX)
87-
c2 = tolower(*p2);
88-
else
89-
{
90-
l = pg_mblen(p2);
91-
(void)pg_mb2wchar_with_len(p2, (pg_wchar *)&c2, l);
92-
c2 = tolower(c2);
93-
}
94-
return(c1 == c2);
78+
/* if one of them is an ASCII while the other is not, then
79+
they must be different characters
80+
*/
81+
else if (*p1 < CHARMAX || *p2 < CHARMAX)
82+
return(0);
83+
84+
/* ok, p1 and p2 are both > CHARMAX, then they must be multi-byte
85+
characters
86+
*/
87+
l = pg_mblen(p1);
88+
(void)pg_mb2wchar_with_len(p1, (pg_wchar *)c1, l);
89+
c1[0] = tolower(c1[0]);
90+
l = pg_mblen(p2);
91+
(void)pg_mb2wchar_with_len(p2, (pg_wchar *)c2, l);
92+
c2[0] = tolower(c2[0]);
93+
return(c1[0] == c2[0]);
9594
}
9695

9796
#endif

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