diff --git a/src/backend/tsearch/dict_ispell.c b/src/backend/tsearch/dict_ispell.c
index 64e2fbe487c17b15ef459dd7c56d629bd322905b..4316c357e13f251d53f5e8f0e6f5ce20cfbf5f42 100644
--- a/src/backend/tsearch/dict_ispell.c
+++ b/src/backend/tsearch/dict_ispell.c
@@ -126,20 +126,19 @@ dispell_lexize(PG_FUNCTION_ARGS)
 	if (res == NULL)
 		PG_RETURN_POINTER(NULL);
 
-	ptr = cptr = res;
-	while (ptr->lexeme)
+	cptr = res;
+	for (ptr = cptr; ptr->lexeme; ptr++)
 	{
 		if (searchstoplist(&(d->stoplist), ptr->lexeme))
 		{
 			pfree(ptr->lexeme);
 			ptr->lexeme = NULL;
-			ptr++;
 		}
 		else
 		{
-			memcpy(cptr, ptr, sizeof(TSLexeme));
+			if (cptr != ptr)
+				memcpy(cptr, ptr, sizeof(TSLexeme));
 			cptr++;
-			ptr++;
 		}
 	}
 	cptr->lexeme = NULL;
diff --git a/src/backend/utils/adt/tsvector.c b/src/backend/utils/adt/tsvector.c
index 6396ad857775d5ffd581465ef9fb7b05f3c53273..9fdaa5b8b9703fc2b33feaa5fdb71f49f8125599 100644
--- a/src/backend/utils/adt/tsvector.c
+++ b/src/backend/utils/adt/tsvector.c
@@ -124,7 +124,8 @@ uniqueentry(WordEntryIN *a, int l, char *buf, int *outbuflen)
 				buflen += res->poslen * sizeof(WordEntryPos) + sizeof(uint16);
 			}
 			res++;
-			memcpy(res, ptr, sizeof(WordEntryIN));
+			if (res != ptr)
+				memcpy(res, ptr, sizeof(WordEntryIN));
 		}
 		else if (ptr->entry.haspos)
 		{