mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-09 10:50:08 +00:00
Properly handle unavailable elements in LC_MONETARY category
This commit is contained in:
parent
728dab0e13
commit
a7931fcfba
16
ChangeLog
16
ChangeLog
@ -1,3 +1,19 @@
|
|||||||
|
2013-11-18 Andreas Schwab <schwab@suse.de>
|
||||||
|
|
||||||
|
* locale/programs/locale.c (show_info) [case byte]: Check for
|
||||||
|
'\377' instead of '\177'.
|
||||||
|
* locale/C-monetary.c (not_available): Always use "\377".
|
||||||
|
* stdlib/strfmon_l.c (__vstrfmon_l): Use -2 as marker for
|
||||||
|
unspecified p_sign_posn and n_sign_posn. Check for '\377' to
|
||||||
|
detect unavailable sign_posn locale elements.
|
||||||
|
* locale/localeconv.c (__localeconv): For grouping and
|
||||||
|
mon_grouping handle "\177" and "\377" like no grouping.
|
||||||
|
(INT_ELEM): New macro. Use it to set all numeric members.
|
||||||
|
* locale/programs/ld-monetary.c (monetary_read)
|
||||||
|
<tok_mon_grouping>: Normalize single -1 to the empty string.
|
||||||
|
* locale/programs/ld-numeric.c (numeric_read) <tok_grouping>:
|
||||||
|
Likewise.
|
||||||
|
|
||||||
2013-11-07 Ondřej Bílka <neleai@seznam.cz>
|
2013-11-07 Ondřej Bílka <neleai@seznam.cz>
|
||||||
|
|
||||||
[BZ #16055]
|
[BZ #16055]
|
||||||
|
@ -21,11 +21,7 @@
|
|||||||
/* This table's entries are taken from POSIX.2 Table 2-9
|
/* This table's entries are taken from POSIX.2 Table 2-9
|
||||||
``LC_MONETARY Category Definition in the POSIX Locale'',
|
``LC_MONETARY Category Definition in the POSIX Locale'',
|
||||||
with additions from ISO 14652, section 4.4. */
|
with additions from ISO 14652, section 4.4. */
|
||||||
#ifdef __CHAR_UNSIGNED__
|
|
||||||
static const char not_available[] = "\377";
|
static const char not_available[] = "\377";
|
||||||
#else
|
|
||||||
static const char not_available[] = "\177";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const struct __locale_data _nl_C_LC_MONETARY attribute_hidden =
|
const struct __locale_data _nl_C_LC_MONETARY attribute_hidden =
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ __localeconv (void)
|
|||||||
result.decimal_point = (char *) _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
|
result.decimal_point = (char *) _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
|
||||||
result.thousands_sep = (char *) _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
|
result.thousands_sep = (char *) _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
|
||||||
result.grouping = (char *) _NL_CURRENT (LC_NUMERIC, GROUPING);
|
result.grouping = (char *) _NL_CURRENT (LC_NUMERIC, GROUPING);
|
||||||
if (*result.grouping == CHAR_MAX || *result.grouping == (char) -1)
|
if (*result.grouping == '\177' || *result.grouping == '\377')
|
||||||
result.grouping = (char *) "";
|
result.grouping = (char *) "";
|
||||||
|
|
||||||
result.int_curr_symbol = (char *) _NL_CURRENT (LC_MONETARY, INT_CURR_SYMBOL);
|
result.int_curr_symbol = (char *) _NL_CURRENT (LC_MONETARY, INT_CURR_SYMBOL);
|
||||||
@ -38,31 +38,29 @@ __localeconv (void)
|
|||||||
result.mon_thousands_sep = (char *) _NL_CURRENT (LC_MONETARY,
|
result.mon_thousands_sep = (char *) _NL_CURRENT (LC_MONETARY,
|
||||||
MON_THOUSANDS_SEP);
|
MON_THOUSANDS_SEP);
|
||||||
result.mon_grouping = (char *) _NL_CURRENT (LC_MONETARY, MON_GROUPING);
|
result.mon_grouping = (char *) _NL_CURRENT (LC_MONETARY, MON_GROUPING);
|
||||||
if (*result.mon_grouping == CHAR_MAX || *result.mon_grouping == (char) -1)
|
if (*result.mon_grouping == '\177' || *result.mon_grouping == '\377')
|
||||||
result.mon_grouping = (char *) "";
|
result.mon_grouping = (char *) "";
|
||||||
result.positive_sign = (char *) _NL_CURRENT (LC_MONETARY, POSITIVE_SIGN);
|
result.positive_sign = (char *) _NL_CURRENT (LC_MONETARY, POSITIVE_SIGN);
|
||||||
result.negative_sign = (char *) _NL_CURRENT (LC_MONETARY, NEGATIVE_SIGN);
|
result.negative_sign = (char *) _NL_CURRENT (LC_MONETARY, NEGATIVE_SIGN);
|
||||||
result.int_frac_digits = *(char *) _NL_CURRENT (LC_MONETARY,
|
|
||||||
INT_FRAC_DIGITS);
|
#define INT_ELEM(member, element) \
|
||||||
result.frac_digits = *(char *) _NL_CURRENT (LC_MONETARY, FRAC_DIGITS);
|
result.member = *(char *) _NL_CURRENT (LC_MONETARY, element); \
|
||||||
result.p_cs_precedes = *(char *) _NL_CURRENT (LC_MONETARY, P_CS_PRECEDES);
|
if (result.member == '\377') result.member = CHAR_MAX
|
||||||
result.p_sep_by_space = *(char *) _NL_CURRENT (LC_MONETARY, P_SEP_BY_SPACE);
|
|
||||||
result.n_cs_precedes = *(char *) _NL_CURRENT (LC_MONETARY, N_CS_PRECEDES);
|
INT_ELEM (int_frac_digits, INT_FRAC_DIGITS);
|
||||||
result.n_sep_by_space = *(char *) _NL_CURRENT (LC_MONETARY, N_SEP_BY_SPACE);
|
INT_ELEM (frac_digits, FRAC_DIGITS);
|
||||||
result.p_sign_posn = *(char *) _NL_CURRENT (LC_MONETARY, P_SIGN_POSN);
|
INT_ELEM (p_cs_precedes, P_CS_PRECEDES);
|
||||||
result.n_sign_posn = *(char *) _NL_CURRENT (LC_MONETARY, N_SIGN_POSN);
|
INT_ELEM (p_sep_by_space, P_SEP_BY_SPACE);
|
||||||
result.int_p_cs_precedes = *(char *) _NL_CURRENT (LC_MONETARY,
|
INT_ELEM (n_cs_precedes, N_CS_PRECEDES);
|
||||||
INT_P_CS_PRECEDES);
|
INT_ELEM (n_sep_by_space, N_SEP_BY_SPACE);
|
||||||
result.int_p_sep_by_space = *(char *) _NL_CURRENT (LC_MONETARY,
|
INT_ELEM (p_sign_posn, P_SIGN_POSN);
|
||||||
INT_P_SEP_BY_SPACE);
|
INT_ELEM (n_sign_posn, N_SIGN_POSN);
|
||||||
result.int_n_cs_precedes = *(char *) _NL_CURRENT (LC_MONETARY,
|
INT_ELEM (int_p_cs_precedes, INT_P_CS_PRECEDES);
|
||||||
INT_N_CS_PRECEDES);
|
INT_ELEM (int_p_sep_by_space, INT_P_SEP_BY_SPACE);
|
||||||
result.int_n_sep_by_space = *(char *) _NL_CURRENT (LC_MONETARY,
|
INT_ELEM (int_n_cs_precedes, INT_N_CS_PRECEDES);
|
||||||
INT_N_SEP_BY_SPACE);
|
INT_ELEM (int_n_sep_by_space, INT_N_SEP_BY_SPACE);
|
||||||
result.int_p_sign_posn = *(char *) _NL_CURRENT (LC_MONETARY,
|
INT_ELEM (int_p_sign_posn, INT_P_SIGN_POSN);
|
||||||
INT_P_SIGN_POSN);
|
INT_ELEM (int_n_sign_posn, INT_N_SIGN_POSN);
|
||||||
result.int_n_sign_posn = *(char *) _NL_CURRENT (LC_MONETARY,
|
|
||||||
INT_N_SIGN_POSN);
|
|
||||||
|
|
||||||
return &result;
|
return &result;
|
||||||
}
|
}
|
||||||
|
@ -677,6 +677,9 @@ monetary_read (struct linereader *ldfile, struct localedef_t *result,
|
|||||||
|
|
||||||
if (!ignore_content)
|
if (!ignore_content)
|
||||||
{
|
{
|
||||||
|
/* A single -1 means no grouping. */
|
||||||
|
if (act == 1 && grouping[0] == '\177')
|
||||||
|
act--;
|
||||||
grouping[act++] = '\0';
|
grouping[act++] = '\0';
|
||||||
|
|
||||||
monetary->mon_grouping = xrealloc (grouping, act);
|
monetary->mon_grouping = xrealloc (grouping, act);
|
||||||
|
@ -305,6 +305,9 @@ numeric_read (struct linereader *ldfile, struct localedef_t *result,
|
|||||||
if (now->tok != tok_eol)
|
if (now->tok != tok_eol)
|
||||||
goto err_label;
|
goto err_label;
|
||||||
|
|
||||||
|
/* A single -1 means no grouping. */
|
||||||
|
if (act == 1 && grouping[0] == '\177')
|
||||||
|
act--;
|
||||||
grouping[act++] = '\0';
|
grouping[act++] = '\0';
|
||||||
|
|
||||||
numeric->grouping = xrealloc (grouping, act);
|
numeric->grouping = xrealloc (grouping, act);
|
||||||
|
@ -895,7 +895,7 @@ show_info (const char *name)
|
|||||||
printf ("%s=", item->name);
|
printf ("%s=", item->name);
|
||||||
|
|
||||||
if (val != NULL)
|
if (val != NULL)
|
||||||
printf ("%d", *val == '\177' ? -1 : *val);
|
printf ("%d", *val == '\377' ? -1 : *val);
|
||||||
putchar ('\n');
|
putchar ('\n');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -158,8 +158,8 @@ __vstrfmon_l (char *s, size_t maxsize, __locale_t loc, const char *format,
|
|||||||
group = 1; /* Print digits grouped. */
|
group = 1; /* Print digits grouped. */
|
||||||
pad = ' '; /* Fill character is <SP>. */
|
pad = ' '; /* Fill character is <SP>. */
|
||||||
is_long_double = 0; /* Double argument by default. */
|
is_long_double = 0; /* Double argument by default. */
|
||||||
p_sign_posn = -1; /* This indicates whether the */
|
p_sign_posn = -2; /* This indicates whether the */
|
||||||
n_sign_posn = -1; /* '(' flag is given. */
|
n_sign_posn = -2; /* '(' flag is given. */
|
||||||
width = -1; /* No width specified so far. */
|
width = -1; /* No width specified so far. */
|
||||||
left = 0; /* Right justified by default. */
|
left = 0; /* Right justified by default. */
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ __vstrfmon_l (char *s, size_t maxsize, __locale_t loc, const char *format,
|
|||||||
group = 0;
|
group = 0;
|
||||||
continue;
|
continue;
|
||||||
case '+': /* Use +/- for sign of number. */
|
case '+': /* Use +/- for sign of number. */
|
||||||
if (n_sign_posn != -1)
|
if (n_sign_posn != -2)
|
||||||
{
|
{
|
||||||
__set_errno (EINVAL);
|
__set_errno (EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
@ -190,7 +190,7 @@ __vstrfmon_l (char *s, size_t maxsize, __locale_t loc, const char *format,
|
|||||||
n_sign_posn = *_NL_CURRENT (LC_MONETARY, N_SIGN_POSN);
|
n_sign_posn = *_NL_CURRENT (LC_MONETARY, N_SIGN_POSN);
|
||||||
continue;
|
continue;
|
||||||
case '(': /* Use ( ) for negative sign. */
|
case '(': /* Use ( ) for negative sign. */
|
||||||
if (n_sign_posn != -1)
|
if (n_sign_posn != -2)
|
||||||
{
|
{
|
||||||
__set_errno (EINVAL);
|
__set_errno (EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
@ -310,16 +310,16 @@ __vstrfmon_l (char *s, size_t maxsize, __locale_t loc, const char *format,
|
|||||||
|
|
||||||
/* If not specified by the format string now find the values for
|
/* If not specified by the format string now find the values for
|
||||||
the format specification. */
|
the format specification. */
|
||||||
if (p_sign_posn == -1)
|
if (p_sign_posn == -2)
|
||||||
p_sign_posn = *_NL_CURRENT (LC_MONETARY, int_format ? INT_P_SIGN_POSN : P_SIGN_POSN);
|
p_sign_posn = *_NL_CURRENT (LC_MONETARY, int_format ? INT_P_SIGN_POSN : P_SIGN_POSN);
|
||||||
if (n_sign_posn == -1)
|
if (n_sign_posn == -2)
|
||||||
n_sign_posn = *_NL_CURRENT (LC_MONETARY, int_format ? INT_N_SIGN_POSN : N_SIGN_POSN);
|
n_sign_posn = *_NL_CURRENT (LC_MONETARY, int_format ? INT_N_SIGN_POSN : N_SIGN_POSN);
|
||||||
|
|
||||||
if (right_prec == -1)
|
if (right_prec == -1)
|
||||||
{
|
{
|
||||||
right_prec = *_NL_CURRENT (LC_MONETARY, int_format ? INT_FRAC_DIGITS : FRAC_DIGITS);
|
right_prec = *_NL_CURRENT (LC_MONETARY, int_format ? INT_FRAC_DIGITS : FRAC_DIGITS);
|
||||||
|
|
||||||
if (right_prec == CHAR_MAX)
|
if (right_prec == '\377')
|
||||||
right_prec = 2;
|
right_prec = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,13 +384,13 @@ __vstrfmon_l (char *s, size_t maxsize, __locale_t loc, const char *format,
|
|||||||
cs_precedes = 1;
|
cs_precedes = 1;
|
||||||
if (other_cs_precedes != 0)
|
if (other_cs_precedes != 0)
|
||||||
other_cs_precedes = 1;
|
other_cs_precedes = 1;
|
||||||
if (sep_by_space == CHAR_MAX)
|
if (sep_by_space == '\377')
|
||||||
sep_by_space = 0;
|
sep_by_space = 0;
|
||||||
if (other_sep_by_space == CHAR_MAX)
|
if (other_sep_by_space == '\377')
|
||||||
other_sep_by_space = 0;
|
other_sep_by_space = 0;
|
||||||
if (sign_posn == CHAR_MAX)
|
if (sign_posn == '\377')
|
||||||
sign_posn = 1;
|
sign_posn = 1;
|
||||||
if (other_sign_posn == CHAR_MAX)
|
if (other_sign_posn == '\377')
|
||||||
other_sign_posn = 1;
|
other_sign_posn = 1;
|
||||||
|
|
||||||
/* Check for degenerate cases */
|
/* Check for degenerate cases */
|
||||||
|
Loading…
Reference in New Issue
Block a user