Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8f91e2b

Browse files
committed
Fix compare bug for tsvector: problem was in aligment. Per Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> and Phil Frost <indigo@bitglue.com>
1 parent 726ede7 commit 8f91e2b

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

contrib/tsearch2/tsvector.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -966,17 +966,43 @@ silly_cmp_tsvector(const tsvector * a, const tsvector * b)
966966
return 1;
967967
else
968968
{
969-
unsigned char *aptr = (unsigned char *) (a->data) + DATAHDRSIZE;
970-
unsigned char *bptr = (unsigned char *) (b->data) + DATAHDRSIZE;
969+
WordEntry *aptr = ARRPTR(a);
970+
WordEntry *bptr = ARRPTR(b);
971+
int i = 0;
972+
int res;
973+
974+
975+
for(i=0;i<a->size;i++) {
976+
if ( aptr->haspos != bptr->haspos ) {
977+
return ( aptr->haspos > bptr->haspos ) ? -1 : 1;
978+
} else if ( aptr->pos != bptr->pos ) {
979+
return ( aptr->pos > bptr->pos ) ? -1 : 1;
980+
} else if ( aptr->len != bptr->len ) {
981+
return ( aptr->len > bptr->len ) ? -1 : 1;
982+
} else if ( (res=strncmp(STRPTR(a) + aptr->pos, STRPTR(b) + bptr->pos, b->len))!= 0 ) {
983+
return res;
984+
} else if ( aptr->haspos ) {
985+
WordEntryPos *ap = POSDATAPTR(a, aptr);
986+
WordEntryPos *bp = POSDATAPTR(b, bptr);
987+
int j;
988+
989+
if ( POSDATALEN(a, aptr) != POSDATALEN(b, bptr) )
990+
return ( POSDATALEN(a, aptr) > POSDATALEN(b, bptr) ) ? -1 : 1;
991+
992+
for(j=0;j<POSDATALEN(a, aptr);j++) {
993+
if ( WEP_GETPOS(*ap) != WEP_GETPOS(*bp) ) {
994+
return ( WEP_GETPOS(*ap) > WEP_GETPOS(*bp) ) ? -1 : 1;
995+
} else if ( WEP_GETWEIGHT(*ap) != WEP_GETWEIGHT(*bp) ) {
996+
return ( WEP_GETWEIGHT(*ap) > WEP_GETWEIGHT(*bp) ) ? -1 : 1;
997+
}
998+
ap++, bp++;
999+
}
1000+
}
9711001

972-
while (aptr - ((unsigned char *) (a->data)) < a->len)
973-
{
974-
if (*aptr != *bptr)
975-
return (*aptr < *bptr) ? -1 : 1;
976-
aptr++;
977-
bptr++;
1002+
aptr++; bptr++;
9781003
}
9791004
}
1005+
9801006
return 0;
9811007
}
9821008

0 commit comments

Comments
 (0)