]> granicus.if.org Git - postgresql/commitdiff
Avoid memcpy() with same source and destination address.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 7 Mar 2014 11:13:33 +0000 (13:13 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 7 Mar 2014 11:29:33 +0000 (13:29 +0200)
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
src/backend/utils/adt/tsvector.c

index f7b7864a0f5ed1b2082a69fe5dd4767f652e7b92..a616915f8de6857b68d96d14c8cae8b81419268f 100644 (file)
@@ -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;
index 8a81f3d8295f85bb9e36898d0ea326a171549890..dbdf0fbe2517a3ff3d7f718d73ab7169025677c9 100644 (file)
@@ -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)
                {