The behavior of that is undefined, although unlikely to lead to problems in
practice.
Found by running regression tests with Valgrind.
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;
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)
{