postgresql/src
Tom Lane a57a6faf60 Make snprintf.c follow the C99 standard for snprintf's result value.
C99 says that the result should be the number of bytes that would have
been emitted given a large enough buffer, not the number we actually
were able to put in the buffer.  It's time to make our substitute
implementation comply with that.  Not doing so results in inefficiency
in buffer-enlargement cases, and also poses a portability hazard for
third-party code that might expect C99-compliant snprintf behavior
within Postgres.

In passing, remove useless tests for str == NULL; neither C99 nor
predecessor standards ever allowed that except when count == 0,
so I see no reason to expend cycles on making that a non-crash case
for this implementation.  Also, don't waste a byte in pg_vfprintf's
local I/O buffer; this might have performance benefits by allowing
aligned writes during flushbuffer calls.

Back-patch of commit 805889d7d.  There was some concern about this
possibly breaking code that assumes pre-C99 behavior, but there is
much more risk (and reality, in our own code) of code that assumes
C99 behavior and hence fails to detect buffer overrun without this.

Discussion: https://postgr.es/m/17245.1534289329@sss.pgh.pa.us
2018-08-15 17:25:24 -04:00
..
backend Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:32 -04:00
bin Fix pg_upgrade to handle event triggers in extensions correctly. 2018-08-07 15:43:49 -04:00
common Unlink static libraries before rebuilding them. 2015-03-01 13:06:39 -05:00
include Stamp 9.3.24. 2018-08-06 16:13:40 -04:00
interfaces Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:32 -04:00
makefiles Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-07-09 17:23:32 -04:00
pl Translation updates 2018-08-06 19:30:02 +02:00
port Make snprintf.c follow the C99 standard for snprintf's result value. 2018-08-15 17:25:24 -04:00
template AIX: Test the -qlonglong option before use. 2015-07-17 03:02:03 -04:00
test Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:32 -04:00
timezone Update time zone data files to tzdata release 2018e. 2018-05-09 13:56:06 -04:00
tools Clear severity 5 perlcritic warnings from vcregress.pl 2018-05-06 07:40:25 -04:00
tutorial Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Create libpgcommon, and move pg_malloc et al to it 2013-02-12 11:21:05 -03:00
Makefile.global.in Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-07-09 17:23:32 -04:00
Makefile.shlib Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-07-09 17:23:32 -04:00
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00