diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-05-09 02:16:00 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-05-09 02:16:00 +0000 |
commit | ed437e2b27c48219a78f3504b0d05c17c2082d02 (patch) | |
tree | 04b0bbedba8b34ef187a5df895cb1cff9a877728 /src/interfaces/libpq/fe-misc.c | |
parent | 54cd4f04576833abc394e131288bf3dd7dcf4806 (diff) | |
download | postgresql-ed437e2b27c48219a78f3504b0d05c17c2082d02.tar.gz postgresql-ed437e2b27c48219a78f3504b0d05c17c2082d02.zip |
Adjust comments about avoiding use of printf's %.*s.
My initial impression that glibc was measuring the precision in characters
(which is what the Linux man page says it does) was incorrect. It does take
the precision to be in bytes, but it also tries to truncate the string at a
character boundary. The bottom line remains the same: it will mess up
if the string is not in the encoding it expects, so we need to avoid %.*s
anytime there's a significant risk of that. Previous code changes are still
good, but adjust the comments to reflect this knowledge. Per research by
Hernan Gonzalez.
Diffstat (limited to 'src/interfaces/libpq/fe-misc.c')
-rw-r--r-- | src/interfaces/libpq/fe-misc.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index 096e0d84a7a..f76168ccd44 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -23,7 +23,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.142 2010/05/08 16:39:53 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.143 2010/05/09 02:16:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -70,8 +70,8 @@ static int pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time); /* * fputnbytes: print exactly N bytes to a file * - * Think not to use fprintf with a %.*s format for this. Some machines - * believe %s's precision is measured in characters, others in bytes. + * We avoid using %.*s here because it can misbehave if the data + * is not valid in what libc thinks is the prevailing encoding. */ static void fputnbytes(FILE *f, const char *str, size_t n) |