git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 77d90d6)
Remove unnecessary type violation in tsvectorrecv().
Wed, 2 Apr 2025 20:17:43 +0000 (16:17 -0400)
Wed, 2 Apr 2025 20:18:03 +0000 (16:18 -0400)
compareentry() is declared to work on WordEntryIN structs, but
tsvectorrecv() is using it in two places to work on WordEntry
structs. This is almost okay, since WordEntry is the first
field 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 compiler
could generate code that depends on the larger alignment.

Given the lack of field reports, this may be just a hypothetical bug
that upsets nothing except sanitizer tools. Or it may be real on
certain hardware but nobody's tried to use tsvectorrecv() on such
hardware. In any case we should fix it, and the fix is trivial:
just change compareentry() so that it works on WordEntry without any
mention of WordEntryIN. We can also get rid of the quite-useless
intermediate function WordEntryCMP.

Bug: #18875
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/18875-07a29c49c825a608@postgresql.org
Backpatch-through: 13


diff --git a/src/backend/utils/adt/tsvector.c b/src/backend/utils/adt/tsvector.c
index cb36893b960703cf2904bdfb43a25a039af6f5cd..4c489d72fe24861951f0c5053cfdbfff8f8afdba 100644 (file)
--- a/src/backend/utils/adt/tsvector.c
+++ b/src/backend/utils/adt/tsvector.c
@@ -22,7 +22,7 @@
typedef struct
{
- WordEntry entry; /* must be first! */
+ WordEntry entry; /* must be first, see compareentry */
WordEntryPos *pos;
int poslen; /* number of elements in pos */
} WordEntryIN;
@@ -78,16 +78,19 @@ uniquePos(WordEntryPos *a, int l)
return res + 1 - a;
}
-/* Compare two WordEntryIN values for qsort */
+/*
+ * Compare two WordEntry structs for qsort_arg. This can also be used on
+ * WordEntryIN structs, since those have WordEntry as their first field.
+ */
static int
compareentry(const void *va, const void *vb, void *arg)
{
- const WordEntryIN *a = (const WordEntryIN *) va;
- const WordEntryIN *b = (const WordEntryIN *) vb;
+ const WordEntry *a = (const WordEntry *) va;
+ const WordEntry *b = (const WordEntry *) vb;
char *BufferStr = (char *) arg;
- return tsCompareString(&BufferStr[a->entry.pos], a->entry.len,
- &BufferStr[b->entry.pos], b->entry.len,
+ return tsCompareString(&BufferStr[a->pos], a->len,
+ &BufferStr[b->pos], b->len,
false);
}
@@ -167,12 +170,6 @@ uniqueentry(WordEntryIN *a, int l, char *buf, int *outbuflen)
return res + 1 - a;
}
-static int
-WordEntryCMP(WordEntry *a, WordEntry *b, char *buf)
-{
- return compareentry(a, b, buf);
-}
-
Datum
tsvectorin(PG_FUNCTION_ARGS)
@@ -505,7 +502,7 @@ tsvectorrecv(PG_FUNCTION_ARGS)
datalen += lex_len;
- if (i > 0 && WordEntryCMP(&vec->entries[i],
+ if (i > 0 && compareentry(&vec->entries[i],
&vec->entries[i - 1],
STRPTR(vec)) <= 0)
needSort = true;
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /