summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-11-25 14:42:10 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2017-11-25 14:42:32 -0500
commit630aceda5be79551b6772ab230fddfc4edbb63eb (patch)
treea76c615cd2aff606973b02358a434d10116b0b56
parent497e79b96135ba6d37cf6b321ad485a2474cb053 (diff)
Avoid formally-undefined use of memcpy() in hstoreUniquePairs().
hstoreUniquePairs() often called memcpy with equal source and destination pointers. Although this is almost surely harmless in practice, it's undefined according to the letter of the C standard. Some versions of valgrind will complain about it, and some versions of libc as well (cf. commit ad520ec4a). Tweak the code to avoid doing that. Noted by Tomas Vondra. Back-patch to all supported versions because of the hazard of libc assertions. Discussion: https://postgr.es/m/bf84d940-90d4-de91-19dd-612e011007f4@fuzzy.cz
-rw-r--r--contrib/hstore/hstore_io.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
index 0c1d99a0150..f763b7cb25b 100644
--- a/contrib/hstore/hstore_io.c
+++ b/contrib/hstore/hstore_io.c
@@ -340,7 +340,8 @@ hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen)
{
*buflen += res->keylen + ((res->isnull) ? 0 : res->vallen);
res++;
- memcpy(res, ptr, sizeof(Pairs));
+ if (res != ptr)
+ memcpy(res, ptr, sizeof(Pairs));
}
ptr++;