diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-10-24 21:43:57 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-10-24 21:43:57 -0400 |
commit | 3147acd63e0135aff9a6c4b01d861251925d97d9 (patch) | |
tree | cd34bf3803b1e3f83bfd3fe58c6d75a9206cfcaf /src/include/lib/stringinfo.h | |
parent | 98c50656cac2e6b873419fd09569a9119c02148c (diff) | |
download | postgresql-3147acd63e0135aff9a6c4b01d861251925d97d9.tar.gz postgresql-3147acd63e0135aff9a6c4b01d861251925d97d9.zip |
Use improved vsnprintf calling logic in more places.
When we are using a C99-compliant vsnprintf implementation (which should be
most places, these days) it is worth the trouble to make use of its report
of how large the buffer needs to be to succeed. This patch adjusts
stringinfo.c and some miscellaneous usages in pg_dump to do that, relying
on the logic recently added in libpgcommon's psprintf.c. Since these
places want to know the number of bytes written once we succeed, modify the
API of pvsnprintf() to report that.
There remains near-duplicate logic in pqexpbuffer.c, but since that code
is in libpq, psprintf.c's approach of exit()-on-error isn't appropriate
for use there. Also note that I didn't bother touching the multitude
of places that call (v)snprintf without any attempt to provide a resizable
buffer.
Release-note-worthy incompatibility: the API of appendStringInfoVA()
changed. If there's any third-party code that's calling that directly,
it will need tweaking along the same lines as in this patch.
David Rowley and Tom Lane
Diffstat (limited to 'src/include/lib/stringinfo.h')
-rw-r--r-- | src/include/lib/stringinfo.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/include/lib/stringinfo.h b/src/include/lib/stringinfo.h index ecb693fcc21..cece81208ed 100644 --- a/src/include/lib/stringinfo.h +++ b/src/include/lib/stringinfo.h @@ -101,11 +101,12 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); * appendStringInfoVA * Attempt to format text data under the control of fmt (an sprintf-style * format string) and append it to whatever is already in str. If successful - * return true; if not (because there's not enough space), return false - * without modifying str. Typically the caller would enlarge str and retry - * on false return --- see appendStringInfo for standard usage pattern. + * return zero; if not (because there's not enough space), return an estimate + * of the space needed, without modifying str. Typically the caller should + * pass the return value to enlargeStringInfo() before trying again; see + * appendStringInfo for standard usage pattern. */ -extern bool +extern int appendStringInfoVA(StringInfo str, const char *fmt, va_list args) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0))); |