Commit bea53dbf by Paolo Carlini Committed by Paolo Carlini

istream.cc (basic_istream<char>::ignore(streamsize), [...]): Avoid _M_gcount overflows.

2005-01-02  Paolo Carlini  <pcarlini@suse.de>

	* 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)): Avoid
	_M_gcount overflows.
	* include/bits/istream.tcc (ignore(streamsize), ignore(streamsize,
	int_type)): Likewise; use snextc in the main loop, consistently
	with the specializations above.

From-SVN: r92816
parent 1330529e
2005-01-02 Paolo Carlini <pcarlini@suse.de>
* 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)): Avoid
_M_gcount overflows.
* include/bits/istream.tcc (ignore(streamsize), ignore(streamsize,
int_type)): Likewise; use snextc in the main loop, consistently
with the specializations above.
2005-01-02 Chris Jefferson <chris@bubblescope.net> 2005-01-02 Chris Jefferson <chris@bubblescope.net>
* include/bits/stl_algobase.h (mismatch): Correct concept check. * include/bits/stl_algobase.h (mismatch): Correct concept check.
......
// istream classes -*- C++ -*- // istream classes -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
// Free Software Foundation, Inc. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -683,13 +683,23 @@ namespace std ...@@ -683,13 +683,23 @@ namespace std
{ {
const int_type __eof = traits_type::eof(); const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __eof; int_type __c = __sb->sgetc();
while (true)
{
while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof))
{
++_M_gcount;
__c = __sb->snextc();
}
if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof))
_M_gcount = 0;
else
break;
}
if (__n != numeric_limits<streamsize>::max())
--__n;
while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
++_M_gcount;
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
} }
...@@ -718,19 +728,32 @@ namespace std ...@@ -718,19 +728,32 @@ namespace std
{ {
const int_type __eof = traits_type::eof(); const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __eof; int_type __c = __sb->sgetc();
while (true)
{
while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
{
++_M_gcount;
__c = __sb->snextc();
}
if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
_M_gcount = 0;
else
break;
}
if (__n != numeric_limits<streamsize>::max())
--__n;
while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
{
++_M_gcount;
if (traits_type::eq_int_type(__c, __delim))
break;
}
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))
{
++_M_gcount;
__sb->sbumpc();
}
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
......
// Input streams -*- C++ -*- // Input streams -*- C++ -*-
// Copyright (C) 2004 Free Software Foundation, Inc. // Copyright (C) 2004, 2005 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -124,28 +124,33 @@ namespace std ...@@ -124,28 +124,33 @@ namespace std
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
const bool __bound = __n != numeric_limits<streamsize>::max(); while (true)
if (__bound)
--__n;
while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c, __eof))
{ {
streamsize __size = __sb->egptr() - __sb->gptr(); while (_M_gcount < __n
if (__bound) && !traits_type::eq_int_type(__c, __eof))
__size = std::min(__size, streamsize(__n - _M_gcount + 1));
if (__size > 1)
{ {
__sb->gbump(__size); streamsize __size = std::min(streamsize(__sb->egptr()
_M_gcount += __size; - __sb->gptr()),
__c = __sb->sgetc(); streamsize(__n - _M_gcount));
if (__size > 1)
{
__sb->gbump(__size);
_M_gcount += __size;
__c = __sb->sgetc();
}
else
{
++_M_gcount;
__c = __sb->snextc();
}
} }
if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof))
_M_gcount == 0;
else else
{ break;
++_M_gcount;
__c = __sb->snextc();
}
} }
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
} }
...@@ -177,34 +182,40 @@ namespace std ...@@ -177,34 +182,40 @@ namespace std
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
const bool __bound = __n != numeric_limits<streamsize>::max(); while (true)
if (__bound)
--__n;
while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
{ {
streamsize __size = __sb->egptr() - __sb->gptr(); while (_M_gcount < __n
if (__bound) && !traits_type::eq_int_type(__c, __eof)
__size = std::min(__size, streamsize(__n - _M_gcount + 1)); && !traits_type::eq_int_type(__c, __delim))
if (__size > 1)
{ {
const char_type* __p = traits_type::find(__sb->gptr(), streamsize __size = std::min(streamsize(__sb->egptr()
__size, - __sb->gptr()),
__cdelim); streamsize(__n - _M_gcount));
if (__p) if (__size > 1)
__size = __p - __sb->gptr(); {
__sb->gbump(__size); const char_type* __p = traits_type::find(__sb->gptr(),
_M_gcount += __size; __size,
__c = __sb->sgetc(); __cdelim);
if (__p)
__size = __p - __sb->gptr();
__sb->gbump(__size);
_M_gcount += __size;
__c = __sb->sgetc();
}
else
{
++_M_gcount;
__c = __sb->snextc();
}
} }
if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
_M_gcount = 0;
else else
{ break;
++_M_gcount;
__c = __sb->snextc();
}
} }
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))
...@@ -390,29 +401,34 @@ namespace std ...@@ -390,29 +401,34 @@ namespace std
const int_type __eof = traits_type::eof(); const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
const bool __bound = __n != numeric_limits<streamsize>::max();
if (__bound)
--__n;
while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c, __eof))
{
streamsize __size = __sb->egptr() - __sb->gptr();
if (__bound)
__size = std::min(__size, streamsize(__n - _M_gcount + 1));
if (__size > 1) while (true)
{
while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof))
{ {
__sb->gbump(__size); streamsize __size = std::min(streamsize(__sb->egptr()
_M_gcount += __size; - __sb->gptr()),
__c = __sb->sgetc(); streamsize(__n - _M_gcount));
if (__size > 1)
{
__sb->gbump(__size);
_M_gcount += __size;
__c = __sb->sgetc();
}
else
{
++_M_gcount;
__c = __sb->snextc();
}
} }
if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof))
_M_gcount == 0;
else else
{ break;
++_M_gcount;
__c = __sb->snextc();
}
} }
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
} }
...@@ -444,34 +460,40 @@ namespace std ...@@ -444,34 +460,40 @@ namespace std
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c = __sb->sgetc();
const bool __bound = __n != numeric_limits<streamsize>::max(); while (true)
if (__bound)
--__n;
while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
{ {
streamsize __size = __sb->egptr() - __sb->gptr(); while (_M_gcount < __n
if (__bound) && !traits_type::eq_int_type(__c, __eof)
__size = std::min(__size, streamsize(__n - _M_gcount + 1)); && !traits_type::eq_int_type(__c, __delim))
if (__size > 1)
{ {
const char_type* __p = traits_type::find(__sb->gptr(), streamsize __size = std::min(streamsize(__sb->egptr()
__size, - __sb->gptr()),
__cdelim); streamsize(__n - _M_gcount));
if (__p) if (__size > 1)
__size = __p - __sb->gptr(); {
__sb->gbump(__size); const char_type* __p = traits_type::find(__sb->gptr(),
_M_gcount += __size; __size,
__c = __sb->sgetc(); __cdelim);
if (__p)
__size = __p - __sb->gptr();
__sb->gbump(__size);
_M_gcount += __size;
__c = __sb->sgetc();
}
else
{
++_M_gcount;
__c = __sb->snextc();
}
} }
if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
_M_gcount = 0;
else else
{ break;
++_M_gcount;
__c = __sb->snextc();
}
} }
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))
......
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