Skip to content

Commit 5f778e6

Browse files
committed
Use memmove() instead of memcpy() for copying overlapping regions.
In commit d2495f2, I fixed this bug in to_tsquery(), but missed the fact that plainto_tsquery() has the same bug.
1 parent c6e5c4d commit 5f778e6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/backend/tsearch/to_tsany.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS)
398398
if (query->size == 0)
399399
PG_RETURN_TSQUERY(query);
400400

401+
/* clean out any stopword placeholders from the tree */
401402
res = clean_fakeval(GETQUERY(query), &len);
402403
if (!res)
403404
{
@@ -407,6 +408,10 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS)
407408
}
408409
memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(QueryItem));
409410

411+
/*
412+
* Removing the stopword placeholders might've resulted in fewer
413+
* QueryItems. If so, move the operands up accordingly.
414+
*/
410415
if (len != query->size)
411416
{
412417
char *oldoperand = GETOPERAND(query);
@@ -415,7 +420,7 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS)
415420
Assert(len < query->size);
416421

417422
query->size = len;
418-
memcpy((void *) GETOPERAND(query), oldoperand, lenoperand);
423+
memmove((void *) GETOPERAND(query), oldoperand, lenoperand);
419424
SET_VARSIZE(query, COMPUTESIZE(len, lenoperand));
420425
}
421426

0 commit comments

Comments
 (0)