Commit 823b4f7d by Benjamin Kosnik

[multiple changes]


2001-12-06  Benjamin Kosnik  <bkoz@redhat.com>

	libstdc++/3720
	* include/bits/locale_facets.tcc (num_put): Clean.
	(num_get::_M_extract_float): Change argument to string.
	(num_get::do_get(float)): Fixup.
	(num_get::do_get(double)): Same.
	(num_get::do_get(long double)): Same.
	(num_get::_M_extract_int): Add maximum length parameter, __max.
	(num_get::_M_extract_float): Correct zeros, use string.
	* include/bits/locale_facets.h (num_get::_M_extract_float): Change
	declaration here.
	* src/locale.cc (__num_base::_S_atoms): Remove x, X.
	* testsuite/27_io/istream_extractor_arith.cc (test13): Add.

2001-12-06  Philip Martin  <pmartin@uklinux.net>

	* testsuite/27_io/istream_extractor_arith.cc (test12): Add
	tests for excess input digits.

From-SVN: r47743
parent a2b1e914
2001-12-06 Benjamin Kosnik <bkoz@redhat.com>
libstdc++/3720
* include/bits/locale_facets.tcc (num_put): Clean.
(num_get::_M_extract_float): Change argument to string.
(num_get::do_get(float)): Fixup.
(num_get::do_get(double)): Same.
(num_get::do_get(long double)): Same.
(num_get::_M_extract_int): Add maximum length parameter, __max.
(num_get::_M_extract_float): Correct zeros, use string.
* include/bits/locale_facets.h (num_get::_M_extract_float): Change
declaration here.
* src/locale.cc (__num_base::_S_atoms): Remove x, X.
* testsuite/27_io/istream_extractor_arith.cc (test13): Add.
2001-12-06 Philip Martin <pmartin@uklinux.net>
* testsuite/27_io/istream_extractor_arith.cc (test12): Add
tests for excess input digits.
2001-12-06 Phil Edwards <pme@gcc.gnu.org>
* include/bits/std_bitset.h: Use GLIBCPP in multiple-inclusion guard.
......@@ -42,7 +62,7 @@
2001-12-04 Paolo Carlini <pcarlini@unitus.it>
libstdc++/4402
* testsuite/27_io/ostream_inserter_arith.cc (test02): add testcase
* testsuite/27_io/ostream_inserter_arith.cc (test02): Add testcase
from the PR.
* include/bits/locale_facets.tcc (num_put::_M_convert_float):
Deal properly with long ios_base::fixed floats.
......
......@@ -420,7 +420,7 @@ namespace std
{
public:
// String literal of acceptable (narrow) input, for num_get.
// "0123456789eEabcdfxABCDFX"
// "0123456789eEabcdfABCDF"
static const char _S_atoms[];
enum
......@@ -428,7 +428,7 @@ namespace std
_M_zero,
_M_e = _M_zero + 10,
_M_E = _M_zero + 11,
_M_size = 23 + 1
_M_size = 21 + 1
};
// Construct and return valid scanf format for floating point types.
......@@ -634,11 +634,11 @@ namespace std
void
_M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
char* __xtrc) const;
string& __xtrc) const;
void
_M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
char* __xtrc, int& __base) const;
char* __xtrc, int __max, int& __base) const;
virtual iter_type
do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
......
......@@ -74,7 +74,7 @@ namespace std
// Definitions for static const data members of locale::id
size_t locale::id::_S_highwater; // init'd to 0 by linker
const char __num_base::_S_atoms[] = "0123456789eEabcdfxABCDFX";
const char __num_base::_S_atoms[] = "0123456789eEabcdfABCDF";
// Definitions for static const data members of locale::_Impl
const locale::id* const
......
......@@ -513,6 +513,83 @@ bool test11()
return test;
}
// libstdc++/3720
// excess input should not cause a core dump
template<typename T>
bool test12_aux(bool integer_type)
{
bool test = true;
int digits_overflow;
if (integer_type)
// This many digits will overflow integer types in base 10.
digits_overflow = std::numeric_limits<T>::digits10 + 1;
else
// This might do it, unsure.
digits_overflow = std::numeric_limits<T>::max_exponent10 + 1;
std::string st;
std::string part = "1234567890123456789012345678901234567890";
for (int i = 0; i < digits_overflow / part.size() + 1; ++i)
st += part;
std::stringbuf sb(st);
std::istream is(&sb);
T t;
is >> t;
VERIFY(is.fail());
return test;
}
bool test12()
{
bool test = true;
VERIFY(test12_aux<short>(true));
VERIFY(test12_aux<int>(true));
VERIFY(test12_aux<long>(true));
VERIFY(test12_aux<float>(false));
VERIFY(test12_aux<double>(false));
VERIFY(test12_aux<long double>(false));
return test;
}
// libstdc++/3720 part two
void test13()
{
using namespace std;
bool test = true;
const char* l1 = "12345678901234567890123456789012345678901234567890123456";
const char* l2 = "1.2345678901234567890123456789012345678901234567890123456"
" "
"1246.9";
// 1
// used to core.
double d;
istringstream iss1(l2);
iss1 >> d;
iss1 >> d;
VERIFY (d > 1246 && d < 1247);
// 2
// quick test for failbit on maximum length extraction.
int i;
int max_digits = numeric_limits<int>::digits10;
string digits;
for (int j = 0; j < max_digits; ++j)
digits += '1';
istringstream iss2(digits);
iss2 >> i;
VERIFY( iss2.good() );
digits += '1';
i = 0;
iss2.str(digits);
iss2.clear();
iss2 >> i;
VERIFY( i == 0 );
VERIFY( iss2.fail() );
}
int main()
{
test01();
......@@ -526,6 +603,7 @@ int main()
test10();
test11();
test12();
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment