diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-08-16 13:01:09 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-08-16 13:01:09 -0400 |
commit | e1d19c902e59ad739cb4b6267ee2073a61e86cd3 (patch) | |
tree | e6090aad9384ba77d324694e2553d02e1d0b7566 /src/backend/utils/misc/guc.c | |
parent | 1eb9221585c25cad1a563bc3414f697dae3fbc8b (diff) | |
download | postgresql-e1d19c902e59ad739cb4b6267ee2073a61e86cd3.tar.gz postgresql-e1d19c902e59ad739cb4b6267ee2073a61e86cd3.zip |
Require a C99-compliant snprintf(), and remove related workarounds.
Since our substitute snprintf now returns a C99-compliant result,
there's no need anymore to have complicated code to cope with pre-C99
behavior. We can just make configure substitute snprintf.c if it finds
that the system snprintf() is pre-C99. (Note: I do not believe that
there are any platforms where this test will trigger that weren't
already being rejected due to our other C99-ish feature requirements for
snprintf. But let's add the check for paranoia's sake.) Then, simplify
the call sites that had logic to cope with the pre-C99 definition.
I also dropped some stuff that was being paranoid about the possibility
of snprintf overrunning the given buffer. The only reports we've ever
heard of that being a problem were for Solaris 7, which is long dead,
and we've sure not heard any reports of these assertions triggering in
a long time. So let's drop that complexity too.
Likewise, drop some code that wasn't trusting snprintf to set errno
when it returns -1. That would be not-per-spec, and again there's
no real reason to believe it is a live issue, especially not for
snprintfs that pass all of configure's feature checks.
Discussion: https://postgr.es/m/17245.1534289329@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/misc/guc.c')
-rw-r--r-- | src/backend/utils/misc/guc.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index f458c0eeae8..9989d3a3517 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -9441,26 +9441,19 @@ do_serialize(char **destptr, Size *maxbytes, const char *fmt,...) if (*maxbytes <= 0) elog(ERROR, "not enough space to serialize GUC state"); - errno = 0; - va_start(vargs, fmt); n = vsnprintf(*destptr, *maxbytes, fmt, vargs); va_end(vargs); - /* - * Cater to portability hazards in the vsnprintf() return value just like - * appendPQExpBufferVA() does. Note that this requires an extra byte of - * slack at the end of the buffer. Since serialize_variable() ends with a - * do_serialize_binary() rather than a do_serialize(), we'll always have - * that slack; estimate_variable_size() need not add a byte for it. - */ - if (n < 0 || n >= *maxbytes - 1) + if (n < 0) { - if (n < 0 && errno != 0 && errno != ENOMEM) - /* Shouldn't happen. Better show errno description. */ - elog(ERROR, "vsnprintf failed: %m"); - else - elog(ERROR, "not enough space to serialize GUC state"); + /* Shouldn't happen. Better show errno description. */ + elog(ERROR, "vsnprintf failed: %m"); + } + if (n >= *maxbytes) + { + /* This shouldn't happen either, really. */ + elog(ERROR, "not enough space to serialize GUC state"); } /* Shift the destptr ahead of the null terminator */ |