[Bug libstdc++/39168] New: Incorrect interpritation of CHAR_MAX inside grouping string in monetary and numeric facets.
tsyvarev at ispras dot ru
Thu Feb 12 15:27:00 GMT 2009
Description of numpunct<>::do_grouping() (18.104.22.168.2, p3):
Returns: A basic_string<char> vec used as a vector of integer values, in which
each element vec[i] represents the number of digits in the group at position i,
starting with position 0 as the rightmost group. If vec.size() <= i, the number
is the same as group (i-1); if (i<0 || vec[i]<=0 || vec[i]==CHAR_MAX), the size
of the digit group is unlimited.
But num_put and num_get implementations don't interpret condition
(vec[i]==CHAR_MAX) as condition of group with unlimited size, but interpret
value CHAR_MAX as regular size of digits group.
According to the code, condition (static_cast<signed char>(vec[i]) > 0) is used
as an indicator of regular group size. This means range 1..127 for vec[i]
But on architectures with char ~ signed char(e.g. x86), CHAR_MAX is 127, so the
range shouldn't include value 127.
In tests, string(1, CHAR_MAX) is used as grouping string. Like string() and
string(1, -1), this should disable grouping at all.
But on architectures with char ~ signed char tests failed. On architectures
with char ~ unsigned char or when CHAR_MAX replaced with -1, all became ok.
Summary: Incorrect interpritation of CHAR_MAX inside grouping
string in monetary and numeric facets.
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tsyvarev at ispras dot ru
More information about the Gcc-bugs