| From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Make printTableAddCell/printTableAddHeader string argument const |
| Date: | 2026-08-11 07:42:18 |
| Message-ID: | E1wth7p-000000005e3-09Qs@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Make printTableAddCell/printTableAddHeader string argument const
These functions would sometimes overwrite the string argument they are
passed, namely via mbvalidate(), which removes invalid UTF-8
characters (or potentially analogously in other encodings, but that is
not implemented). However, many callers are not expecting that. In
many callers, the input value comes directly from libpq structures,
such as from PQgetvalue() or PQsslAttribute(). The latter actually
has a const char * return type, and that was cast away. But even the
former is not expecting its return value to be modified.
Fix that by making these arguments const. Internally, we add a
separate function that does only the checking part of mbvalidate().
Only if the validation returns a negative result, we make a copy and
run mbvalidate() on the copy. printTableAddCell() already had
internal infrastructure for keeping track of what values needed to be
freed. We add the same for printTableAddHeader().
In passing, also simplify the code a bit. There were essentially
duplicate mechanisms for keeping track of the most recently added
cell (fields .cell and .cellsadded). Make that consistent by using an
integer counter for everything. That makes the code arguably easier
to read than with the "current pointer" approaches.
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/flat/c855d318-4545-4dc7-b466-2e24fbf64725%40eisentraut.org
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/c83a133f2bb531fe56284e35809c14eed1d8bd6e
Modified Files
--------------
src/bin/psql/command.c | 20 ++++-----
src/fe_utils/mbprint.c | 33 ++++++++++++++
src/fe_utils/print.c | 97 +++++++++++++++++++++++++++++++++---------
src/include/fe_utils/mbprint.h | 1 +
src/include/fe_utils/print.h | 11 +++--
5 files changed, 125 insertions(+), 37 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2026-08-11 18:25:42 | pgsql: Fix pg_strupper/lower/title/fold() functions to work with C loca |
| Previous Message | David Rowley | 2026-08-11 01:30:27 | pgsql: Show estimated number of groups for Incremental Sort in EXPLAIN |