1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

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".
This commit is contained in:
Tom Lane
2010-05-08 16:39:53 +00:00
parent 71a185a24d
commit 54cd4f0457
11 changed files with 111 additions and 31 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.218 2010/04/03 20:55:57 tgl Exp $
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.219 2010/05/08 16:39:51 tgl Exp $
*/
#include "postgres_fe.h"
#include "command.h"
@ -651,6 +651,13 @@ exec_command(const char *cmd,
{
char *opt = psql_scan_slash_option(scan_state,
OT_WHOLE_LINE, NULL, false);
size_t len;
/* strip any trailing spaces and semicolons */
len = strlen(opt);
while (len > 0 &&
(isspace((unsigned char) opt[len - 1]) || opt[len - 1] == ';'))
opt[--len] = '\0';
helpSQL(opt, pset.popt.topt.pager);
free(opt);