Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c6a4f2

Browse files
committed
Remove unnecessary type violation in tsvectorrecv().
compareentry() is declared to work on WordEntryIN structs, buttsvectorrecv() is using it in two places to work on WordEntrystructs. This is almost okay, since WordEntry is the firstfield of WordEntryIN. But on machines with 8-byte pointers,WordEntryIN will have a larger alignment spec than WordEntry,and it's at least theoretically possible that the compilercould generate code that depends on the larger alignment.Given the lack of field reports, this may be just a hypothetical bugthat upsets nothing except sanitizer tools. Or it may be real oncertain hardware but nobody's tried to use tsvectorrecv() on suchhardware. In any case we should fix it, and the fix is trivial:just change compareentry() so that it works on WordEntry without anymention of WordEntryIN. We can also get rid of the quite-uselessintermediate function WordEntryCMP.Bug: #18875Reported-by: Alexander Lakhin <exclusion@gmail.com>Author: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/18875-07a29c49c825a608@postgresql.orgBackpatch-through: 13
1 parentb9ec812 commit2c6a4f2

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

‎src/backend/utils/adt/tsvector.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
typedefstruct
2424
{
25-
WordEntryentry;/* must be first! */
25+
WordEntryentry;/* must be first, see compareentry */
2626
WordEntryPos*pos;
2727
intposlen;/* number of elements in pos */
2828
}WordEntryIN;
@@ -78,16 +78,19 @@ uniquePos(WordEntryPos *a, int l)
7878
returnres+1-a;
7979
}
8080

81-
/* Compare two WordEntryIN values for qsort */
81+
/*
82+
* Compare two WordEntry structs for qsort_arg. This can also be used on
83+
* WordEntryIN structs, since those have WordEntry as their first field.
84+
*/
8285
staticint
8386
compareentry(constvoid*va,constvoid*vb,void*arg)
8487
{
85-
constWordEntryIN*a= (constWordEntryIN*)va;
86-
constWordEntryIN*b= (constWordEntryIN*)vb;
88+
constWordEntry*a= (constWordEntry*)va;
89+
constWordEntry*b= (constWordEntry*)vb;
8790
char*BufferStr= (char*)arg;
8891

89-
returntsCompareString(&BufferStr[a->entry.pos],a->entry.len,
90-
&BufferStr[b->entry.pos],b->entry.len,
92+
returntsCompareString(&BufferStr[a->pos],a->len,
93+
&BufferStr[b->pos],b->len,
9194
false);
9295
}
9396

@@ -167,12 +170,6 @@ uniqueentry(WordEntryIN *a, int l, char *buf, int *outbuflen)
167170
returnres+1-a;
168171
}
169172

170-
staticint
171-
WordEntryCMP(WordEntry*a,WordEntry*b,char*buf)
172-
{
173-
returncompareentry(a,b,buf);
174-
}
175-
176173

177174
Datum
178175
tsvectorin(PG_FUNCTION_ARGS)
@@ -505,7 +502,7 @@ tsvectorrecv(PG_FUNCTION_ARGS)
505502

506503
datalen+=lex_len;
507504

508-
if (i>0&&WordEntryCMP(&vec->entries[i],
505+
if (i>0&&compareentry(&vec->entries[i],
509506
&vec->entries[i-1],
510507
STRPTR(vec)) <=0)
511508
needSort= true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp