Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc961f40

Browse files
committed
Further fix for psql's code for locale-aware formatting of numeric output.
(Third time's the charm, I hope.)Additional testing disclosed that this code could mangle already-localizedoutput from the "money" datatype. We can't very easily skip applying itto "money" values, because the logic is tied to column right-justificationand people expect "money" output to be right-justified. Short ofdecoupling that, we can fix it in what should be a safe enough way bytesting to make sure the string doesn't contain any characters that wouldnot be expected in plain numeric output.
1 parent49917ed commitc961f40

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

‎src/bin/psql/print.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,34 @@ additional_numeric_locale_len(const char *my_str)
161161
}
162162

163163
/*
164+
* Format a numeric value per current LC_NUMERIC locale setting
165+
*
164166
* Returns the appropriately formatted string in a new allocated block,
165-
* caller must free
167+
* caller must free.
168+
*
169+
* setDecimalLocale() must have been called earlier.
166170
*/
167171
staticchar*
168172
format_numeric_locale(constchar*my_str)
169173
{
170-
intnew_len=strlen(my_str)+additional_numeric_locale_len(my_str);
171-
char*new_str=pg_malloc(new_len+1);
172-
intint_len=integer_digits(my_str);
173-
inti,
174-
leading_digits;
175-
intnew_str_pos=0;
174+
char*new_str;
175+
intnew_len,
176+
int_len,
177+
leading_digits,
178+
i,
179+
new_str_pos;
180+
181+
/*
182+
* If the string doesn't look like a number, return it unchanged. This
183+
* check is essential to avoid mangling already-localized "money" values.
184+
*/
185+
if (strspn(my_str,"0123456789+-.eE")!=strlen(my_str))
186+
returnpg_strdup(my_str);
187+
188+
new_len=strlen(my_str)+additional_numeric_locale_len(my_str);
189+
new_str=pg_malloc(new_len+1);
190+
new_str_pos=0;
191+
int_len=integer_digits(my_str);
176192

177193
/* number of digits in first thousands group */
178194
leading_digits=int_len %groupdigits;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp