pgsql: Work around a subtle portability problem in use of printf %s - Mailing list pgsql-committers

From tgl@postgresql.org (Tom Lane)
Subject pgsql: Work around a subtle portability problem in use of printf %s
Date
Msg-id 20100508164003.B1B217541D3@cvs.postgresql.org
Whole thread Raw
List pgsql-committers
Log Message:
-----------
Work around a subtle portability problem in use of printf %s format.
Depending on which spec you read, field widths and precisions in %s may be
counted either in bytes or characters.  Our code was assuming bytes, which
is wrong at least for glibc's implementation, and in any case libc might
have a different idea of the prevailing encoding than we do.  Hence, for
portable results we must avoid using anything more complex than just "%s"
unless the string to be printed is known to be all-ASCII.

This patch fixes the cases I could find, including the psql formatting
failure reported by Hernan Gonzalez.  In HEAD only, I also added comments
to some places where it appears safe to continue using "%.*s".

Tags:
----
REL8_4_STABLE

Modified Files:
--------------
    pgsql/src/backend/parser:
        scansup.c (r1.37 -> r1.37.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/scansup.c?r1=1.37&r2=1.37.2.1)
    pgsql/src/backend/utils/error:
        elog.c (r1.216 -> r1.216.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/error/elog.c?r1=1.216&r2=1.216.2.1)
    pgsql/src/bin/psql:
        print.c (r1.116.2.3 -> r1.116.2.4)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/bin/psql/print.c?r1=1.116.2.3&r2=1.116.2.4)
    pgsql/src/interfaces/libpq:
        fe-misc.c (r1.140 -> r1.140.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/fe-misc.c?r1=1.140&r2=1.140.2.1)

pgsql-committers by date:

Previous
From: tgl@postgresql.org (Tom Lane)
Date:
Subject: pgsql: Work around a subtle portability problem in use of printf %s
Next
From: tgl@postgresql.org (Tom Lane)
Date:
Subject: pgsql: Work around a subtle portability problem in use of printf %s