Neil Conway <nconway@klamath.dyndns.org> writes:
> Apparently, you need to make two calls to appendPQExpBuffer() to
> use fmtId() twice, because it uses a static buffer (thanks for
> spotting this Tom).
I think people have been bit by that before. It's fairly easy to miss
at present, because fmtId only uses the static buffer if it decides to
quote the name. If your test case doesn't exercise that path, you'll
not notice the problem.
We could improve the odds at a cost of a small number of cycles, by
having fmtId copy the name into its static buffer even if it doesn't
need to quote. Then the buffer would always be used, and erroneous
reuse of fmtId should be pretty obvious.
(In case anyone's about to suggest that we avoid the problem by
malloc'ing the result, the trouble with that approach is it means
memory leakage --- at least unless the call sites are uglified
quite a lot to free the returned strings after use. I like this
way better; but we should try to make it a tad less error-prone.)
Any objections?
regards, tom lane