Commit 55f53543 authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

Fix bttextcmp() to use unsigned char*.

#ifdef USE_LOCALE added.
parent cbaa9883
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.7 1997/04/07 06:45:41 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.8 1997/04/18 02:48:05 vadim Exp $
* *
* NOTES * NOTES
* These functions are stored in pg_amproc. For each operator class * These functions are stored in pg_amproc. For each operator class
...@@ -134,19 +134,37 @@ btnamecmp(NameData *a, NameData *b) ...@@ -134,19 +134,37 @@ btnamecmp(NameData *a, NameData *b)
int32 int32
bttextcmp(struct varlena *a, struct varlena *b) bttextcmp(struct varlena *a, struct varlena *b)
{ {
char *ap, *bp; unsigned char *ap, *bp;
int len;
int res; int res;
#ifdef USE_LOCALE
int la = VARSIZE(a) - VARHDRSZ;
int lb = VARSIZE(b) - VARHDRSZ;
ap = VARDATA(a); ap = (unsigned char *) palloc (la + 1);
bp = VARDATA(b); bp = (unsigned char *) palloc (lb + 1);
memcpy(ap, VARDATA(a), la);
*(ap + la) = '\0';
memcpy(bp, VARDATA(b), lb);
*(bp + lb) = '\0';
res = strcoll (ap, bp);
pfree (ap);
pfree (bp);
#else
int len = VARSIZE(a);
/* len is the length of the shorter of the two strings */ /* len is the length of the shorter of the two strings */
if ((len = VARSIZE(a)) > VARSIZE(b)) if ( len > VARSIZE(b) )
len = VARSIZE(b); len = VARSIZE(b);
/* len includes the four bytes in which string length is stored */ len -= VARHDRSZ;
len -= sizeof(VARSIZE(a));
ap = VARDATA(a);
bp = VARDATA(b);
/* /*
* If the two strings differ in the first len bytes, or if they're * 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) ...@@ -161,6 +179,8 @@ bttextcmp(struct varlena *a, struct varlena *b)
len--; len--;
} while (res == 0 && len != 0); } while (res == 0 && len != 0);
} }
#endif
if (res != 0 || VARSIZE(a) == VARSIZE(b)) if (res != 0 || VARSIZE(a) == VARSIZE(b))
return (res); return (res);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment