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/backend/tsearch/wparser_def.c | |
parent | 71a185a24d573dc1449777ff9fa8f3020af6f13c (diff) | |
download | postgresql-54cd4f04576833abc394e131288bf3dd7dcf4806.tar.gz |
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/backend/tsearch/wparser_def.c')
-rw-r--r-- | src/backend/tsearch/wparser_def.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c index a2da9210c4..d2e47ceaf5 100644 --- a/src/backend/tsearch/wparser_def.c +++ b/src/backend/tsearch/wparser_def.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tsearch/wparser_def.c,v 1.30 2010/04/28 02:04:16 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tsearch/wparser_def.c,v 1.31 2010/05/08 16:39:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -322,6 +322,12 @@ TParserInit(char *str, int len) prs->state->state = TPS_Base; #ifdef WPARSER_TRACE + /* + * Use of %.*s here is not portable when the string contains multibyte + * characters: some machines interpret the length in characters, others + * in bytes. Since it's only a debugging aid, we haven't bothered to + * fix this. + */ fprintf(stderr, "parsing \"%.*s\"\n", len, str); #endif @@ -361,6 +367,7 @@ TParserCopyInit(const TParser *orig) prs->state->state = TPS_Base; #ifdef WPARSER_TRACE + /* See note above about %.*s */ fprintf(stderr, "parsing copy of \"%.*s\"\n", prs->lenstr, prs->str); #endif |