aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2005-01-05 11:11:48 +0000
committerPaolo Carlini <pcarlini@suse.de>2005-01-05 11:11:48 +0000
commit68445e3ce55d10b78dbb42e807c31786139b007b (patch)
tree080e0c96b4e24522fb5299998ff72b047a27e916 /libstdc++-v3
parentfdddff595a1ffdcf5a3e7ad791e0784d1a083ba4 (diff)
2005-01-05 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)): At the end, first check _M_gcount vs __n. * include/bits/istream.tcc (ignore(streamsize), ignore(streamsize, int_type)): Likewise. * testsuite/27_io/basic_istream/ignore/char/4.cc: New. * testsuite/27_io/basic_istream/ignore/wchar_t/4.cc: Likewise. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@92947 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog12
-rw-r--r--libstdc++-v3/include/bits/istream.tcc16
-rw-r--r--libstdc++-v3/src/istream.cc19
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/4.cc59
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/4.cc59
5 files changed, 155 insertions, 10 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 12119bf3695..8322d5f9efc 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,15 @@
+2005-01-05 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)): At the end,
+ first check _M_gcount vs __n.
+ * include/bits/istream.tcc (ignore(streamsize), ignore(streamsize,
+ int_type)): Likewise.
+ * testsuite/27_io/basic_istream/ignore/char/4.cc: New.
+ * testsuite/27_io/basic_istream/ignore/wchar_t/4.cc: Likewise.
+
2005-01-03 Mark Mitchell <mark@codesourcery.com>
* testsuite/testsuite_hooks.cc: Use __throw_exception_again
diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc
index 573c179615e..876f626acfc 100644
--- a/libstdc++-v3/include/bits/istream.tcc
+++ b/libstdc++-v3/include/bits/istream.tcc
@@ -685,6 +685,13 @@ namespace std
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
+ // N.B. On LFS-enabled platforms streamsize is still 32 bits
+ // wide: if we want to implement the standard mandated behavior
+ // for n == max() (see 27.6.1.3/24) we are at risk of signed
+ // integer overflow: thus these contortions. Also note that,
+ // by definition, when more than 2G chars are actually ignored,
+ // _M_gcount (the return value of gcount, that is) cannot be
+ // really correct, being unavoidably too small.
while (true)
{
while (_M_gcount < __n
@@ -700,7 +707,7 @@ namespace std
break;
}
- if (traits_type::eq_int_type(__c, __eof))
+ if (_M_gcount < __n)
__err |= ios_base::eofbit;
}
catch(...)
@@ -730,6 +737,7 @@ namespace std
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
+ // See comment above.
while (true)
{
while (_M_gcount < __n
@@ -747,9 +755,11 @@ namespace std
break;
}
- if (traits_type::eq_int_type(__c, __eof))
+ if (_M_gcount == __n)
+ ;
+ else if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
- else if (traits_type::eq_int_type(__c, __delim))
+ else
{
++_M_gcount;
__sb->sbumpc();
diff --git a/libstdc++-v3/src/istream.cc b/libstdc++-v3/src/istream.cc
index 5bdcaaf6b59..dc99051a022 100644
--- a/libstdc++-v3/src/istream.cc
+++ b/libstdc++-v3/src/istream.cc
@@ -123,7 +123,8 @@ namespace std
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
-
+
+ // See comment in istream.tcc.
while (true)
{
while (_M_gcount < __n
@@ -151,7 +152,7 @@ namespace std
break;
}
- if (traits_type::eq_int_type(__c, __eof))
+ if (_M_gcount < __n)
__err |= ios_base::eofbit;
}
catch(...)
@@ -216,9 +217,11 @@ namespace std
break;
}
- if (traits_type::eq_int_type(__c, __eof))
+ if (_M_gcount == __n)
+ ;
+ else if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
- else if (traits_type::eq_int_type(__c, __delim))
+ else
{
++_M_gcount;
__sb->sbumpc();
@@ -429,7 +432,7 @@ namespace std
break;
}
- if (traits_type::eq_int_type(__c, __eof))
+ if (_M_gcount < __n)
__err |= ios_base::eofbit;
}
catch(...)
@@ -494,9 +497,11 @@ namespace std
break;
}
- if (traits_type::eq_int_type(__c, __eof))
+ if (_M_gcount == __n)
+ ;
+ else if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
- else if (traits_type::eq_int_type(__c, __delim))
+ else
{
++_M_gcount;
__sb->sbumpc();
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/4.cc
new file mode 100644
index 00000000000..474f6a9d04c
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/4.cc
@@ -0,0 +1,59 @@
+// 2005-01-05 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005 Free Software Foundation
+//
+// 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.6.1.3 unformatted input functions
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ const string str_01("Gesang der junglinge");
+ ios_base::iostate state1, state2;
+
+ stringbuf isbuf_01(str_01, ios_base::in);
+ istream is_01(&isbuf_01);
+
+ state1 = is_01.rdstate();
+ VERIFY( state1 == ios_base::goodbit );
+
+ is_01.ignore(11, 'j');
+ VERIFY( is_01.gcount() == 11 );
+ state2 = is_01.rdstate();
+ VERIFY( state2 == state1 );
+ VERIFY( is_01.peek() == 'j' );
+
+ is_01.ignore(9);
+ VERIFY( is_01.gcount() == 9 );
+ state2 = is_01.rdstate();
+ VERIFY( state2 == state1 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/4.cc
new file mode 100644
index 00000000000..361811754ce
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/4.cc
@@ -0,0 +1,59 @@
+// 2005-01-05 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005 Free Software Foundation
+//
+// 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.6.1.3 unformatted input functions
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ const wstring str_01(L"Gesang der junglinge");
+ ios_base::iostate state1, state2;
+
+ wstringbuf isbuf_01(str_01, ios_base::in);
+ wistream is_01(&isbuf_01);
+
+ state1 = is_01.rdstate();
+ VERIFY( state1 == ios_base::goodbit );
+
+ is_01.ignore(11, L'j');
+ VERIFY( is_01.gcount() == 11 );
+ state2 = is_01.rdstate();
+ VERIFY( state2 == state1 );
+ VERIFY( is_01.peek() == L'j' );
+
+ is_01.ignore(9);
+ VERIFY( is_01.gcount() == 9 );
+ state2 = is_01.rdstate();
+ VERIFY( state2 == state1 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}