Avoid memcpy() with same source and destination address.

The behavior of that is undefined, although unlikely to lead to problems in
practice.

Found by running regression tests with Valgrind.
REL8_4_STABLE
Heikki Linnakangas 12 years ago
parent fb61ff85e1
commit ff9d757c67
  1. 7
      src/backend/tsearch/dict_ispell.c
  2. 1
      src/backend/utils/adt/tsvector.c

@ -127,20 +127,19 @@ dispell_lexize(PG_FUNCTION_ARGS)
if (res == NULL) if (res == NULL)
PG_RETURN_POINTER(NULL); PG_RETURN_POINTER(NULL);
ptr = cptr = res; cptr = res;
while (ptr->lexeme) for (ptr = cptr; ptr->lexeme; ptr++)
{ {
if (searchstoplist(&(d->stoplist), ptr->lexeme)) if (searchstoplist(&(d->stoplist), ptr->lexeme))
{ {
pfree(ptr->lexeme); pfree(ptr->lexeme);
ptr->lexeme = NULL; ptr->lexeme = NULL;
ptr++;
} }
else else
{ {
if (cptr != ptr)
memcpy(cptr, ptr, sizeof(TSLexeme)); memcpy(cptr, ptr, sizeof(TSLexeme));
cptr++; cptr++;
ptr++;
} }
} }
cptr->lexeme = NULL; cptr->lexeme = NULL;

@ -125,6 +125,7 @@ uniqueentry(WordEntryIN *a, int l, char *buf, int *outbuflen)
buflen += res->poslen * sizeof(WordEntryPos) + sizeof(uint16); buflen += res->poslen * sizeof(WordEntryPos) + sizeof(uint16);
} }
res++; res++;
if (res != ptr)
memcpy(res, ptr, sizeof(WordEntryIN)); memcpy(res, ptr, sizeof(WordEntryIN));
} }
else if (ptr->entry.haspos) else if (ptr->entry.haspos)

Loading…
Cancel
Save