aboutsummaryrefslogtreecommitdiff
path: root/src/common/psprintf.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-12-06 15:08:44 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2018-12-06 15:08:44 -0500
commitd2b0b60e71931997455afd5da72ca29148f1ca51 (patch)
tree6d9d9b54df3d60bc7ffc9580e7556abc1f193498 /src/common/psprintf.c
parent7a55ccc477b58863f6c73c243c7adb79c9717eda (diff)
downloadpostgresql-d2b0b60e71931997455afd5da72ca29148f1ca51.tar.gz
postgresql-d2b0b60e71931997455afd5da72ca29148f1ca51.zip
Improve our response to invalid format strings, and detect more cases.
Places that are testing for *printf failure ought to include the format string in their error reports, since bad-format-string is one of the more likely causes of such failure. This both makes it easier to find and repair the mistake, and provides at least some useful info to the user who stumbles across such a problem. Also, tighten snprintf.c to report EINVAL for an invalid flag or final character in a format %-spec (including the case where the %-spec is missing a final character altogether). This seems like better project policy, and it also allows removing an instruction or two from the hot code path. Back-patch the error reporting change in pvsnprintf, since it should be harmless and may be helpful; but not the snprintf.c change. Per discussion of bug #15511 from Ertuğrul Kahveci, which reported an invalid translated format string. These changes don't fix that error, but they should improve matters next time we make such a mistake. Discussion: https://postgr.es/m/15511-1d8b6a0bc874112f@postgresql.org
Diffstat (limited to 'src/common/psprintf.c')
-rw-r--r--src/common/psprintf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/common/psprintf.c b/src/common/psprintf.c
index 2cf100f0954..411713bac84 100644
--- a/src/common/psprintf.c
+++ b/src/common/psprintf.c
@@ -113,9 +113,9 @@ pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)
if (unlikely(nprinted < 0))
{
#ifndef FRONTEND
- elog(ERROR, "vsnprintf failed: %m");
+ elog(ERROR, "vsnprintf failed: %m with format string \"%s\"", fmt);
#else
- fprintf(stderr, "vsnprintf failed: %s\n", strerror(errno));
+ fprintf(stderr, "vsnprintf failed: %m with format string \"%s\"\n", fmt);
exit(EXIT_FAILURE);
#endif
}