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 20100508163953.756987541D2@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".

Modified Files:
--------------
    pgsql/src/backend/lib:
        stringinfo.c (r1.52 -> r1.53)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/lib/stringinfo.c?r1=1.52&r2=1.53)
    pgsql/src/backend/parser:
        scansup.c (r1.39 -> r1.40)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/scansup.c?r1=1.39&r2=1.40)
    pgsql/src/backend/tsearch:
        wparser_def.c (r1.30 -> r1.31)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/tsearch/wparser_def.c?r1=1.30&r2=1.31)
    pgsql/src/backend/utils/adt:
        datetime.c (r1.210 -> r1.211)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/datetime.c?r1=1.210&r2=1.211)
    pgsql/src/backend/utils/error:
        elog.c (r1.223 -> r1.224)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/error/elog.c?r1=1.223&r2=1.224)
    pgsql/src/bin/psql:
        command.c (r1.218 -> r1.219)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/bin/psql/command.c?r1=1.218&r2=1.219)
        help.c (r1.157 -> r1.158)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/bin/psql/help.c?r1=1.157&r2=1.158)
        print.c (r1.124 -> r1.125)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/bin/psql/print.c?r1=1.124&r2=1.125)
    pgsql/src/interfaces/ecpg/ecpglib:
        error.c (r1.25 -> r1.26)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/ecpg/ecpglib/error.c?r1=1.25&r2=1.26)
    pgsql/src/interfaces/ecpg/pgtypeslib:
        dt_common.c (r1.51 -> r1.52)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c?r1=1.51&r2=1.52)
    pgsql/src/interfaces/libpq:
        fe-misc.c (r1.141 -> r1.142)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/fe-misc.c?r1=1.141&r2=1.142)

pgsql-committers by date:

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