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

Commitda4af91

Browse files
committed
Further fix for psql's code for locale-aware formatting of numeric output.
On closer inspection, those seemingly redundant atoi() calls were not somuch inefficient as just plain wrong: the author of this code either hadnot read, or had not understood, the POSIX specification for localeconv().The grouping field is *not* a textual digit string but separate integersencoded as chars.We'll follow the existing code as well as the backend's cash.c in onlyhonoring the first group width, but let's at least honor it correctly.This doesn't actually result in any behavioral change in any of thelocales I have installed on my Linux box, which may explain why nobody'scomplained; grouping width 3 is close enough to universal that it's barelyworth considering other cases. Still, wrong is wrong, so back-patch.
1 parentf1ee153 commitda4af91

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

‎src/bin/psql/print.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,16 +3227,24 @@ setDecimalLocale(void)
32273227

32283228
extlconv=localeconv();
32293229

3230+
/* Don't accept an empty decimal_point string */
32303231
if (*extlconv->decimal_point)
32313232
decimal_point=pg_strdup(extlconv->decimal_point);
32323233
else
32333234
decimal_point=".";/* SQL output standard */
32343235

3235-
if (*extlconv->grouping&&atoi(extlconv->grouping)>0)
3236-
groupdigits=atoi(extlconv->grouping);
3237-
else
3236+
/*
3237+
* Although the Open Group standard allows locales to supply more than one
3238+
* group width, we consider only the first one, and we ignore any attempt
3239+
* to suppress grouping by specifying CHAR_MAX. As in the backend's
3240+
* cash.c, we must apply a range check to avoid being fooled by variant
3241+
* CHAR_MAX values.
3242+
*/
3243+
groupdigits=*extlconv->grouping;
3244+
if (groupdigits <=0||groupdigits>6)
32383245
groupdigits=3;/* most common */
32393246

3247+
/* Don't accept an empty thousands_sep string, either */
32403248
/* similar code exists in formatting.c */
32413249
if (*extlconv->thousands_sep)
32423250
thousands_sep=pg_strdup(extlconv->thousands_sep);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp