Re: valgrind error in tsvectorin - Mailing list pgsql-hackers

From Tom Lane
Subject Re: valgrind error in tsvectorin
Date
Msg-id 3274.1242342130@sss.pgh.pa.us
Whole thread Raw
In response to Re: valgrind error in tsvectorin  (Greg Stark <stark@enterprisedb.com>)
List pgsql-hackers
Greg Stark <stark@enterprisedb.com> writes:
>> Yeah, it looks like the memcpy is sometimes unnecessary because res and
>> ptr point to the same place. �It might be worth cleaning up just to
>> avoid the valgrind warning, but I doubt it would save any noticeable
>> number of cycles.

> I assume valgrind is warning about it because memcpy's behaviour is
> undefined if the blocks overlap. I'm having trouble imagining an
> implementation that would fail if they're precisely the same pointer
> though.

Me either.  A counterexample is that compilers typically implement
structure assignment via memcpy, and the behavior of "*d = *s" is
not undefined merely because d and s point to the same place.

In this particular example it looks like res and ptr might be the same
often enough that adding an "if (res != ptr)" test would save enough
cycles to be worth its cost ... but it's pretty marginal.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [COMMITTERS] pgsql: Translation updates
Next
From: Tom Lane
Date:
Subject: Re: [COMMITTERS] pgsql: Translation updates