mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
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
This commit is contained in:
@ -98,14 +98,16 @@ extern char *MemoryContextStrdup(MemoryContext context, const char *string);
|
||||
extern char *pstrdup(const char *in);
|
||||
extern char *pnstrdup(const char *in, Size len);
|
||||
|
||||
/* sprintf into a palloc'd buffer */
|
||||
extern char *psprintf(const char *fmt,...)
|
||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
|
||||
|
||||
/* basic memory allocation functions */
|
||||
extern void *palloc(Size size);
|
||||
extern void *palloc0(Size size);
|
||||
extern void pfree(void *pointer);
|
||||
extern void *repalloc(void *pointer, Size size);
|
||||
|
||||
/* sprintf into a palloc'd buffer --- these are in psprintf.c */
|
||||
extern char *psprintf(const char *fmt,...)
|
||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
|
||||
extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)
|
||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
|
||||
|
||||
#endif /* PALLOC_H */
|
||||
|
Reference in New Issue
Block a user