Skip to content

Commit 55f5354

Browse files
committed
Fix bttextcmp() to use unsigned char*.
#ifdef USE_LOCALE added.
1 parent cbaa988 commit 55f5354

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/backend/access/nbtree/nbtcompare.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.7 1997/04/07 06:45:41 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.8 1997/04/18 02:48:05 vadim Exp $
1111
*
1212
* NOTES
1313
* These functions are stored in pg_amproc. For each operator class
@@ -134,19 +134,37 @@ btnamecmp(NameData *a, NameData *b)
134134
int32
135135
bttextcmp(struct varlena *a, struct varlena *b)
136136
{
137-
char *ap, *bp;
138-
int len;
137+
unsigned char *ap, *bp;
139138
int res;
139+
140+
#ifdef USE_LOCALE
141+
int la = VARSIZE(a) - VARHDRSZ;
142+
int lb = VARSIZE(b) - VARHDRSZ;
140143

141-
ap = VARDATA(a);
142-
bp = VARDATA(b);
144+
ap = (unsigned char *) palloc (la + 1);
145+
bp = (unsigned char *) palloc (lb + 1);
146+
147+
memcpy(ap, VARDATA(a), la);
148+
*(ap + la) = '\0';
149+
memcpy(bp, VARDATA(b), lb);
150+
*(bp + lb) = '\0';
151+
152+
res = strcoll (ap, bp);
153+
154+
pfree (ap);
155+
pfree (bp);
156+
157+
#else
158+
int len = VARSIZE(a);
143159

144160
/* len is the length of the shorter of the two strings */
145-
if ((len = VARSIZE(a)) > VARSIZE(b))
161+
if ( len > VARSIZE(b) )
146162
len = VARSIZE(b);
147-
148-
/* len includes the four bytes in which string length is stored */
149-
len -= sizeof(VARSIZE(a));
163+
164+
len -= VARHDRSZ;
165+
166+
ap = VARDATA(a);
167+
bp = VARDATA(b);
150168

151169
/*
152170
* If the two strings differ in the first len bytes, or if they're
@@ -161,6 +179,8 @@ bttextcmp(struct varlena *a, struct varlena *b)
161179
len--;
162180
} while (res == 0 && len != 0);
163181
}
182+
183+
#endif
164184

165185
if (res != 0 || VARSIZE(a) == VARSIZE(b))
166186
return (res);

0 commit comments

Comments
 (0)