Commit 78593d78 by Paolo Carlini Committed by Paolo Carlini

istream.cc (basic_istream<char>::ignore(streamsize), [...]): In case more than…

istream.cc (basic_istream<char>::ignore(streamsize), [...]): In case more than numeric_limits<streamsize>::max() chars are skipped...

2005-01-11  Paolo Carlini  <pcarlini@suse.de>
	    Benjamin Kosnik  <bkoz@redhat.com>

	* src/istream.cc (basic_istream<char>::ignore(streamsize),
	basic_istream<char>::ignore(streamsize, int_type),
	basic_istream<wchar_t>::ignore(streamsize),
	basic_istream<wchar_t>::ignore(streamsize, int_type)): In case
	more than numeric_limits<streamsize>::max() chars are skipped,
	set _M_gcount = max().
	* include/bits/istream.tcc (ignore(streamsize), ignore(streamsize,
	int_type)): Likewise; keep simple, don't forward.

Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com>

From-SVN: r93208
parent bc7566ca
2005-01-11 Paolo Carlini <pcarlini@suse.de> 2005-01-11 Paolo Carlini <pcarlini@suse.de>
Benjamin Kosnik <bkoz@redhat.com>
* src/istream.cc (basic_istream<char>::ignore(streamsize),
basic_istream<char>::ignore(streamsize, int_type),
basic_istream<wchar_t>::ignore(streamsize),
basic_istream<wchar_t>::ignore(streamsize, int_type)): In case
more than numeric_limits<streamsize>::max() chars are skipped,
set _M_gcount = max().
* include/bits/istream.tcc (ignore(streamsize), ignore(streamsize,
int_type)): Likewise; keep simple, don't forward.
2005-01-11 Paolo Carlini <pcarlini@suse.de>
* src/istream.cc (basic_istream<char>::ignore(streamsize), * src/istream.cc (basic_istream<char>::ignore(streamsize),
basic_istream<char>::ignore(streamsize, int_type), basic_istream<char>::ignore(streamsize, int_type),
......
...@@ -671,9 +671,6 @@ namespace std ...@@ -671,9 +671,6 @@ namespace std
basic_istream<_CharT, _Traits>:: basic_istream<_CharT, _Traits>::
ignore(streamsize __n) ignore(streamsize __n)
{ {
if (__n == 1)
return ignore();
_M_gcount = 0; _M_gcount = 0;
sentry __cerb(*this, true); sentry __cerb(*this, true);
if (__cerb && __n > 0) if (__cerb && __n > 0)
...@@ -692,6 +689,7 @@ namespace std ...@@ -692,6 +689,7 @@ namespace std
// by definition, when more than 2G chars are actually ignored, // by definition, when more than 2G chars are actually ignored,
// _M_gcount (the return value of gcount, that is) cannot be // _M_gcount (the return value of gcount, that is) cannot be
// really correct, being unavoidably too small. // really correct, being unavoidably too small.
bool __large_ignore = false;
while (true) while (true)
{ {
while (_M_gcount < __n while (_M_gcount < __n
...@@ -702,11 +700,17 @@ namespace std ...@@ -702,11 +700,17 @@ namespace std
} }
if (__n == numeric_limits<streamsize>::max() if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof)) && !traits_type::eq_int_type(__c, __eof))
{
_M_gcount = numeric_limits<streamsize>::min(); _M_gcount = numeric_limits<streamsize>::min();
__large_ignore = true;
}
else else
break; break;
} }
if (__large_ignore)
_M_gcount = numeric_limits<streamsize>::max();
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
} }
...@@ -723,9 +727,6 @@ namespace std ...@@ -723,9 +727,6 @@ namespace std
basic_istream<_CharT, _Traits>:: basic_istream<_CharT, _Traits>::
ignore(streamsize __n, int_type __delim) ignore(streamsize __n, int_type __delim)
{ {
if (traits_type::eq_int_type(__delim, traits_type::eof()))
return ignore(__n);
_M_gcount = 0; _M_gcount = 0;
sentry __cerb(*this, true); sentry __cerb(*this, true);
if (__cerb && __n > 0) if (__cerb && __n > 0)
...@@ -738,6 +739,7 @@ namespace std ...@@ -738,6 +739,7 @@ namespace std
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
// See comment above. // See comment above.
bool __large_ignore = false;
while (true) while (true)
{ {
while (_M_gcount < __n while (_M_gcount < __n
...@@ -750,15 +752,22 @@ namespace std ...@@ -750,15 +752,22 @@ namespace std
if (__n == numeric_limits<streamsize>::max() if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof) && !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim)) && !traits_type::eq_int_type(__c, __delim))
{
_M_gcount = numeric_limits<streamsize>::min(); _M_gcount = numeric_limits<streamsize>::min();
__large_ignore = true;
}
else else
break; break;
} }
if (__large_ignore)
_M_gcount = numeric_limits<streamsize>::max();
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __delim)) else if (traits_type::eq_int_type(__c, __delim))
{ {
if (_M_gcount < numeric_limits<streamsize>::max())
++_M_gcount; ++_M_gcount;
__sb->sbumpc(); __sb->sbumpc();
} }
......
...@@ -125,6 +125,7 @@ namespace std ...@@ -125,6 +125,7 @@ namespace std
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
// See comment in istream.tcc. // See comment in istream.tcc.
bool __large_ignore = false;
while (true) while (true)
{ {
while (_M_gcount < __n while (_M_gcount < __n
...@@ -147,11 +148,17 @@ namespace std ...@@ -147,11 +148,17 @@ namespace std
} }
if (__n == numeric_limits<streamsize>::max() if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof)) && !traits_type::eq_int_type(__c, __eof))
{
_M_gcount = numeric_limits<streamsize>::min(); _M_gcount = numeric_limits<streamsize>::min();
__large_ignore = true;
}
else else
break; break;
} }
if (__large_ignore)
_M_gcount = numeric_limits<streamsize>::max();
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
} }
...@@ -183,6 +190,7 @@ namespace std ...@@ -183,6 +190,7 @@ namespace std
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
bool __large_ignore = false;
while (true) while (true)
{ {
while (_M_gcount < __n while (_M_gcount < __n
...@@ -212,15 +220,22 @@ namespace std ...@@ -212,15 +220,22 @@ namespace std
if (__n == numeric_limits<streamsize>::max() if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof) && !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim)) && !traits_type::eq_int_type(__c, __delim))
{
_M_gcount = numeric_limits<streamsize>::min(); _M_gcount = numeric_limits<streamsize>::min();
__large_ignore = true;
}
else else
break; break;
} }
if (__large_ignore)
_M_gcount = numeric_limits<streamsize>::max();
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __delim)) else if (traits_type::eq_int_type(__c, __delim))
{ {
if (_M_gcount < numeric_limits<streamsize>::max())
++_M_gcount; ++_M_gcount;
__sb->sbumpc(); __sb->sbumpc();
} }
...@@ -403,6 +418,7 @@ namespace std ...@@ -403,6 +418,7 @@ namespace std
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
bool __large_ignore = false;
while (true) while (true)
{ {
while (_M_gcount < __n while (_M_gcount < __n
...@@ -425,11 +441,17 @@ namespace std ...@@ -425,11 +441,17 @@ namespace std
} }
if (__n == numeric_limits<streamsize>::max() if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof)) && !traits_type::eq_int_type(__c, __eof))
{
_M_gcount = numeric_limits<streamsize>::min(); _M_gcount = numeric_limits<streamsize>::min();
__large_ignore = true;
}
else else
break; break;
} }
if (__large_ignore)
_M_gcount = numeric_limits<streamsize>::max();
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
} }
...@@ -461,6 +483,7 @@ namespace std ...@@ -461,6 +483,7 @@ namespace std
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
bool __large_ignore = false;
while (true) while (true)
{ {
while (_M_gcount < __n while (_M_gcount < __n
...@@ -490,15 +513,22 @@ namespace std ...@@ -490,15 +513,22 @@ namespace std
if (__n == numeric_limits<streamsize>::max() if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof) && !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim)) && !traits_type::eq_int_type(__c, __delim))
{
_M_gcount = numeric_limits<streamsize>::min(); _M_gcount = numeric_limits<streamsize>::min();
__large_ignore = true;
}
else else
break; break;
} }
if (__large_ignore)
_M_gcount = numeric_limits<streamsize>::max();
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __delim)) else if (traits_type::eq_int_type(__c, __delim))
{ {
if (_M_gcount < numeric_limits<streamsize>::max())
++_M_gcount; ++_M_gcount;
__sb->sbumpc(); __sb->sbumpc();
} }
......
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