@@ -340,6 +340,7 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
340
340
if (query -> size == 0 )
341
341
PG_RETURN_TSQUERY (query );
342
342
343
+ /* clean out any stopword placeholders from the tree */
343
344
res = clean_fakeval (GETQUERY (query ),& len );
344
345
if (!res )
345
346
{
@@ -349,6 +350,10 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
349
350
}
350
351
memcpy ((void * )GETQUERY (query ), (void * )res ,len * sizeof (QueryItem ));
351
352
353
+ /*
354
+ * Removing the stopword placeholders might've resulted in fewer
355
+ * QueryItems. If so, move the operands up accordingly.
356
+ */
352
357
if (len != query -> size )
353
358
{
354
359
char * oldoperand = GETOPERAND (query );
@@ -357,7 +362,7 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
357
362
Assert (len < query -> size );
358
363
359
364
query -> size = len ;
360
- memcpy ((void * )GETOPERAND (query ),oldoperand ,VARSIZE (query )- (oldoperand - (char * )query ));
365
+ memmove ((void * )GETOPERAND (query ),oldoperand ,VARSIZE (query )- (oldoperand - (char * )query ));
361
366
SET_VARSIZE (query ,COMPUTESIZE (len ,lenoperand ));
362
367
}
363
368