mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
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.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.125 2010/05/08 16:39:52 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.126 2010/05/09 02:15:59 tgl Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
|
||||
@ -255,8 +255,8 @@ format_numeric_locale(const char *my_str)
|
||||
/*
|
||||
* 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)
|
||||
|
Reference in New Issue
Block a user