From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Simplify correct use of simple_prompt().
Date: Tue, 30 Aug 2016 21:02:16 +0000
Message-ID: <E1beqAi-0003v5-2C@gemulon.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>
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>
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/9daec77e165de461fca9d5bc3ece86a91aba5804
Modified Files
--------------
contrib/oid2name/oid2name.c | 13 ++++++-----
contrib/vacuumlo/vacuumlo.c | 17 +++++++++------
src/bin/initdb/initdb.c | 23 ++++++++------------
src/bin/pg_basebackup/nls.mk | 1 +
src/bin/pg_basebackup/streamutil.c | 14 ++++++------
src/bin/pg_dump/pg_backup_db.c | 35 ++++++++++++------------------
src/bin/pg_dump/pg_dumpall.c | 17 +++++++++------
src/bin/pgbench/pgbench.c | 10 +++++----
src/bin/psql/command.c | 25 +++++++++++-----------
src/bin/psql/startup.c | 16 ++++++++------
src/bin/scripts/common.c | 34 +++++++++++------------------
src/bin/scripts/createuser.c | 21 +++++++++++-------
src/bin/scripts/dropuser.c | 7 +++++-
src/include/port.h | 3 ++-
src/port/sprompt.c | 44 +++++++++++++++-----------------------
15 files changed, 138 insertions(+), 142 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Simplify correct use of simple_prompt().
In-Reply-To: <E1beqAi-0003v5-2C@gemulon.postgresql.org>
References: <E1beqAi-0003v5-2C@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox