Skip to content

Commit d8f2858

Browse files
committed
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.
1 parent 762c143 commit d8f2858

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/backend/tsearch/dict_ispell.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,19 @@ dispell_lexize(PG_FUNCTION_ARGS)
127127
if (res == NULL)
128128
PG_RETURN_POINTER(NULL);
129129

130-
ptr = cptr = res;
131-
while (ptr->lexeme)
130+
cptr = res;
131+
for (ptr = cptr; ptr->lexeme; ptr++)
132132
{
133133
if (searchstoplist(&(d->stoplist), ptr->lexeme))
134134
{
135135
pfree(ptr->lexeme);
136136
ptr->lexeme = NULL;
137-
ptr++;
138137
}
139138
else
140139
{
141-
memcpy(cptr, ptr, sizeof(TSLexeme));
140+
if (cptr != ptr)
141+
memcpy(cptr, ptr, sizeof(TSLexeme));
142142
cptr++;
143-
ptr++;
144143
}
145144
}
146145
cptr->lexeme = NULL;

src/backend/utils/adt/tsvector.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ uniqueentry(WordEntryIN *a, int l, char *buf, int *outbuflen)
125125
buflen += res->poslen * sizeof(WordEntryPos) + sizeof(uint16);
126126
}
127127
res++;
128-
memcpy(res, ptr, sizeof(WordEntryIN));
128+
if (res != ptr)
129+
memcpy(res, ptr, sizeof(WordEntryIN));
129130
}
130131
else if (ptr->entry.haspos)
131132
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy