Skip to content

Commit c7a186e

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 ff2e0e1 commit c7a186e

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

131-
ptr = cptr = res;
132-
while (ptr->lexeme)
131+
cptr = res;
132+
for (ptr = cptr; ptr->lexeme; ptr++)
133133
{
134134
if (searchstoplist(&(d->stoplist), ptr->lexeme))
135135
{
136136
pfree(ptr->lexeme);
137137
ptr->lexeme = NULL;
138-
ptr++;
139138
}
140139
else
141140
{
142-
memcpy(cptr, ptr, sizeof(TSLexeme));
141+
if (cptr != ptr)
142+
memcpy(cptr, ptr, sizeof(TSLexeme));
143143
cptr++;
144-
ptr++;
145144
}
146145
}
147146
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