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
This commit is contained in:
Paolo Carlini 2005-01-03 00:02:47 +00:00 committed by Paolo Carlini
parent 1330529e58
commit bea53dbfbc
3 changed files with 155 additions and 99 deletions

View File

@ -1,3 +1,14 @@
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>
* include/bits/stl_algobase.h (mismatch): Correct concept check.

View File

@ -1,6 +1,6 @@
// 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.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -683,13 +683,23 @@ namespace std
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __eof;
int_type __c = __sb->sgetc();
if (__n != numeric_limits<streamsize>::max())
--__n;
while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
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 (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
@ -718,19 +728,32 @@ namespace std
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __eof;
int_type __c = __sb->sgetc();
if (__n != numeric_limits<streamsize>::max())
--__n;
while (_M_gcount <= __n
&& !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
while (true)
{
while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
{
++_M_gcount;
if (traits_type::eq_int_type(__c, __delim))
__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 (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __delim))
{
++_M_gcount;
__sb->sbumpc();
}
}
catch(...)
{ this->_M_setstate(ios_base::badbit); }

View File

@ -1,6 +1,6 @@
// 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
// software; you can redistribute it and/or modify it under the
@ -124,16 +124,14 @@ namespace std
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
const bool __bound = __n != numeric_limits<streamsize>::max();
if (__bound)
--__n;
while (_M_gcount <= __n
while (true)
{
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));
streamsize __size = std::min(streamsize(__sb->egptr()
- __sb->gptr()),
streamsize(__n - _M_gcount));
if (__size > 1)
{
__sb->gbump(__size);
@ -146,6 +144,13 @@ namespace std
__c = __sb->snextc();
}
}
if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof))
_M_gcount == 0;
else
break;
}
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
@ -177,17 +182,15 @@ namespace std
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
const bool __bound = __n != numeric_limits<streamsize>::max();
if (__bound)
--__n;
while (_M_gcount <= __n
while (true)
{
while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
{
streamsize __size = __sb->egptr() - __sb->gptr();
if (__bound)
__size = std::min(__size, streamsize(__n - _M_gcount + 1));
streamsize __size = std::min(streamsize(__sb->egptr()
- __sb->gptr()),
streamsize(__n - _M_gcount));
if (__size > 1)
{
const char_type* __p = traits_type::find(__sb->gptr(),
@ -205,6 +208,14 @@ namespace std
__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 (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __delim))
@ -391,16 +402,14 @@ namespace std
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
const bool __bound = __n != numeric_limits<streamsize>::max();
if (__bound)
--__n;
while (_M_gcount <= __n
while (true)
{
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));
streamsize __size = std::min(streamsize(__sb->egptr()
- __sb->gptr()),
streamsize(__n - _M_gcount));
if (__size > 1)
{
__sb->gbump(__size);
@ -413,6 +422,13 @@ namespace std
__c = __sb->snextc();
}
}
if (__n == numeric_limits<streamsize>::max()
&& !traits_type::eq_int_type(__c, __eof))
_M_gcount == 0;
else
break;
}
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
@ -444,17 +460,15 @@ namespace std
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
const bool __bound = __n != numeric_limits<streamsize>::max();
if (__bound)
--__n;
while (_M_gcount <= __n
while (true)
{
while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
{
streamsize __size = __sb->egptr() - __sb->gptr();
if (__bound)
__size = std::min(__size, streamsize(__n - _M_gcount + 1));
streamsize __size = std::min(streamsize(__sb->egptr()
- __sb->gptr()),
streamsize(__n - _M_gcount));
if (__size > 1)
{
const char_type* __p = traits_type::find(__sb->gptr(),
@ -472,6 +486,14 @@ namespace std
__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 (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __delim))