postgresql/src/bin/initdb
Tom Lane 9daec77e16 Simplify correct use of simple_prompt().
The previous API for this function had it returning a malloc'd string.
That meant that callers had to check for NULL return, which few of them
were doing, and it also meant that callers had to remember to free()
the string later, which required extra logic in most cases.

Instead, make simple_prompt() write into a buffer supplied by the caller.
Anywhere that the maximum required input length is reasonably small,
which is almost all of the callers, we can just use a local or static
array as the buffer instead of dealing with malloc/free.

A fair number of callers used "pointer == NULL" as a proxy for "haven't
requested the password yet".  Maintaining the same behavior requires
adding a separate boolean flag for that, which adds back some of the
complexity we save by removing free()s.  Nonetheless, this nets out
at a small reduction in overall code size, and considerably less code
than we would have had if we'd added the missing NULL-return checks
everywhere they were needed.

In passing, clean up the API comment for simple_prompt() and get rid
of a very-unnecessary malloc/free in its Windows code path.

This is nominally a bug fix, but it does not seem worth back-patching,
because the actual risk of an OOM failure in any of these places seems
pretty tiny, and all of them are client-side not server-side anyway.

This patch is by me, but it owes a great deal to Michael Paquier
who identified the problem and drafted a patch for fixing it the
other way.

Discussion: <CAB7nPqRu07Ot6iht9i9KRfYLpDaF2ZuUv5y_+72uP23ZAGysRg@mail.gmail.com>
2016-08-30 17:02:02 -04:00
..
po Translation updates 2016-08-08 11:08:00 -04:00
t Fix typo in TAP test identification string. 2016-05-23 20:04:27 -04:00
.gitignore Add TAP tests for client programs 2014-04-14 21:33:46 -04:00
Makefile initdb now needs submake-libpq and submake-libpgfeutils. 2016-08-22 08:01:12 -04:00
findtimezone.c Update Windows timezone mapping from Windows 7 and 10 2016-08-18 12:32:42 +02:00
initdb.c Simplify correct use of simple_prompt(). 2016-08-30 17:02:02 -04:00
nls.mk Translation updates 2016-05-09 10:04:41 -04:00