pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix an assortment of improper usages of string functions
Date: Tue, 06 Sep 2022 01:21:38 +0000
Message-ID: <E1oVNHV-001dVW-Qp@gemulon.postgresql.org> (raw)

Fix an assortment of improper usages of string functions

In a similar effort to f736e188c and 110d81728, fixup various usages of
string functions where a more appropriate function is available and more
fit for purpose.

These changes include:

1. Use cstring_to_text_with_len() instead of cstring_to_text() when
   working with a StringInfoData and the length can easily be obtained.
2. Use appendStringInfoString() instead of appendStringInfo() when no
   formatting is required.
3. Use pstrdup(...) instead of psprintf("%s", ...)
4. Use pstrdup(...) instead of psprintf(...) (with no formatting)
5. Use appendPQExpBufferChar() instead of appendPQExpBufferStr() when the
   length of the string being appended is 1.
6. appendStringInfoChar() instead of appendStringInfo() when no formatting
   is required and string is 1 char long.
7. Use appendPQExpBufferStr(b, .) instead of appendPQExpBuffer(b, "%s", .)
8. Don't use pstrdup when it's fine to just point to the string constant.

I (David) did find other cases of #8 but opted to use #4 instead as I
wasn't certain enough that applying #8 was ok (e.g in hba.c)

Author: Ranier Vilela, David Rowley
Discussion: https://postgr.es/m/CAApHDvo2j2+RJBGhNtUz6BxabWWh2Jx16wMUMWKUjv70Ver1vg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8b26769bc441fffa8aad31dddc484c2f4043d2c9

Modified Files
--------------
contrib/hstore/hstore_io.c                  |   4 +-
contrib/sepgsql/schema.c                    |   2 +-
src/backend/access/brin/brin_minmax_multi.c |  10 +-
src/backend/access/rmgrdesc/xlogdesc.c      |   4 +-
src/backend/jit/llvm/llvmjit.c              |   2 +-
src/backend/libpq/hba.c                     |   4 +-
src/backend/postmaster/postmaster.c         |   2 +-
src/backend/replication/logical/tablesync.c |   4 +-
src/backend/utils/adt/date.c                |   2 +-
src/backend/utils/adt/misc.c                |   2 +-
src/backend/utils/adt/ruleutils.c           |  10 +-
src/backend/utils/adt/timestamp.c           |   2 +-
src/bin/pg_amcheck/pg_amcheck.c             |  46 +--
src/bin/pg_dump/pg_dump.c                   | 444 ++++++++++++++--------------
src/bin/pg_dump/pg_dumpall.c                |   2 +-
src/bin/pgbench/pgbench.c                   |   9 +-
src/bin/psql/command.c                      |   4 +-
src/bin/psql/describe.c                     |   8 +-
18 files changed, 277 insertions(+), 284 deletions(-)



Message-ID: <E1oVNHV-001dVW-Qp@gemulon.postgresql.org>
Permalink:  ../E1oVNHV-001dVW-Qp@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1oVNHV-001dVW-Qp@gemulon.postgresql.org

 · 

reply

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: drowley@postgresql.org
  Subject: Re: pgsql: Fix an assortment of improper usages of string functions
  In-Reply-To: <E1oVNHV-001dVW-Qp@gemulon.postgresql.org>
  References: <E1oVNHV-001dVW-Qp@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