Re: valgrind error in tsvectorin

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Stark <stark(at)enterprisedb(dot)com>
Cc: Postgres <pgsql-hackers(at)postgresql(dot)org>, Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>, Teodor Sigaev <teodor(at)sigaev(dot)ru>
Subject: Re: valgrind error in tsvectorin
Date: 2009-05-14 23:02:10
Message-ID: 3274.1242342130@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greg Stark <stark(at)enterprisedb(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-05-14 23:06:43 Re: [COMMITTERS] pgsql: Translation updates
Previous Message Alvaro Herrera 2009-05-14 22:41:25 Re: [COMMITTERS] pgsql: Translation updates