diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-05-08 16:39:53 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-05-08 16:39:53 +0000 |
commit | 54cd4f04576833abc394e131288bf3dd7dcf4806 (patch) | |
tree | 0772e1bedbca8466701b6a116e065e7a00959ebd /src/bin/psql/command.c | |
parent | 71a185a24d573dc1449777ff9fa8f3020af6f13c (diff) |
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".
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 4a94a1ace12..b9624451c35 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -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); |