Content-Length: 316503 | pFad | https://github.com/postgrespro/postgres/commit/ad7b48ea08d6c33bae0a33c5f2a06272293c0f2f

A6 Avoid memcpy() with same source and destination address. · postgrespro/postgres@ad7b48e · GitHub
Skip to content

Commit ad7b48e

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 2b8483d commit ad7b48e

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
@@ -126,20 +126,19 @@ dispell_lexize(PG_FUNCTION_ARGS)
126126
if (res == NULL)
127127
PG_RETURN_POINTER(NULL);
128128

129-
ptr = cptr = res;
130-
while (ptr->lexeme)
129+
cptr = res;
130+
for (ptr = cptr; ptr->lexeme; ptr++)
131131
{
132132
if (searchstoplist(&(d->stoplist), ptr->lexeme))
133133
{
134134
pfree(ptr->lexeme);
135135
ptr->lexeme = NULL;
136-
ptr++;
137136
}
138137
else
139138
{
140-
memcpy(cptr, ptr, sizeof(TSLexeme));
139+
if (cptr != ptr)
140+
memcpy(cptr, ptr, sizeof(TSLexeme));
141141
cptr++;
142-
ptr++;
143142
}
144143
}
145144
cptr->lexeme = NULL;

src/backend/utils/adt/tsvector.c

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

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/postgrespro/postgres/commit/ad7b48ea08d6c33bae0a33c5f2a06272293c0f2f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy