Make printTableAddCell/printTableAddHeader string argument const

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Make printTableAddCell/printTableAddHeader string argument const
Date: 2026-08-04 09:36:52
Message-ID: c855d318-4545-4dc7-b466-2e24fbf64725@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

These functions are used in psql to assemble tables to print.

They 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.

The first three patches are preparation patches to further clean up the
nearby code a bit.

Attachment Content-Type Size
0001-Remove-useless-confusing-const-qualifiers.patch text/plain 4.5 KB
0002-Remove-useless-ENABLE_NLS-conditionals.patch text/plain 1.8 KB
0003-Use-frontend-logging-API-in-fe_utils-print.c.patch text/plain 3.0 KB
0004-Make-printTableAddCell-printTableAddHeader-string-ar.patch text/plain 11.9 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message solai v 2026-08-04 09:43:11 Re: pg_xmin_horizon: a system view of everything pinning the xmin horizon
Previous Message Peter Smith 2026-08-04 09:10:06 Re: Add more tab=completion rules for DROP PROPERTY GRAPH