On Wed, Oct 23, 2013 at 4:00 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Yeah. As a separate matter, it might be useful to revise stringinfo.c
and the asprintf code so that *if* the returned value is larger than the given buffer size, we use it as a guide to resizing, avoiding the possible need to loop multiple times to make the buffer large enough. And we could also improve our own implementation of snprintf to follow the C99 spec.
Attached is a draft patch which implements this.
I didn't bother making the translation macros make use of the extra data as I
didn't think we would have many translations long enough to take advantage of it.
I think it's a good idea to take advantage of the buffer size if vsnprintf() has gone
to the trouble of working out what is needed for us. It seems quite wasteful to throw this information away.