postgres.git / summary / log / commit / refs
commit 8332fe76b559dd7d0a689ec66e96c359e67e1f3b
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Fri Mar 07 11:13:33 2014 +0000
First released in: 9.4.0, 8.4.21, 9.0.17, 9.1.13, 9.2.8, 9.3.4
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.
src/backend/tsearch/dict_ispell.c | 9 ++++-----
src/backend/utils/adt/tsvector.c | 3 ++-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/backend/tsearch/dict_ispell.c b/src/backend/tsearch/dict_ispell.c
index 425b810d055..5cca3b64f0d 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 fc8a318da3c..609b0721bef 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)
{
[parent: 886c4ebfa3d9]