aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Lennox <lennox@cs.columbia.edu>2002-11-18 22:42:35 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2002-11-18 22:42:35 +0000
commit5bdb1440a1e11b17ed56abdf15fb302064345565 (patch)
treeedf898092def4d7c35d3378fd2bf0d5592a37073
parent8c9aa0cba995b8db154e154161a9d1c8fc9753ee (diff)
downloadgcc-5bdb1440a1e11b17ed56abdf15fb302064345565.zip
gcc-5bdb1440a1e11b17ed56abdf15fb302064345565.tar.gz
gcc-5bdb1440a1e11b17ed56abdf15fb302064345565.tar.bz2
streambuf.tcc (__copy_streambufs): verify __sbin->gptr() + __bufsize < __sbin->egptr() before using.
2002-11-18 Jonathan Lennox <lennox@cs.columbia.edu> * include/bits/streambuf.tcc (__copy_streambufs): verify __sbin->gptr() + __bufsize < __sbin->egptr() before using. * testsuite/27_io/ostream_inserter_other.cc (test_buffer_4): Add. (test05): Use test_buffer_4. Delete unused ostringstream variables. From-SVN: r59234
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/bits/streambuf.tcc3
-rw-r--r--libstdc++-v3/testsuite/27_io/ostream_inserter_other.cc30
3 files changed, 38 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 7934d74..6798340 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,11 @@
+2002-11-18 Jonathan Lennox <lennox@cs.columbia.edu>
+
+ * include/bits/streambuf.tcc (__copy_streambufs): verify
+ __sbin->gptr() + __bufsize < __sbin->egptr() before using.
+ * testsuite/27_io/ostream_inserter_other.cc (test_buffer_4): Add.
+ (test05): Use test_buffer_4. Delete unused ostringstream
+ variables.
+
2002-11-18 Paolo Carlini <pcarlini@unitus.it>
PR libstdc++/6745 (continued)
diff --git a/libstdc++-v3/include/bits/streambuf.tcc b/libstdc++-v3/include/bits/streambuf.tcc
index cdaab2e..2862dff 100644
--- a/libstdc++-v3/include/bits/streambuf.tcc
+++ b/libstdc++-v3/include/bits/streambuf.tcc
@@ -213,7 +213,8 @@ namespace std
{
while (__testput && __bufsize != -1)
{
- if (__bufsize != 0 && __sbin->gptr() != NULL)
+ if (__bufsize != 0 && __sbin->gptr() != NULL
+ && __sbin->gptr() + __bufsize <= __sbin->egptr())
{
__xtrct = __sbout->sputn(__sbin->gptr(), __bufsize);
__ret += __xtrct;
diff --git a/libstdc++-v3/testsuite/27_io/ostream_inserter_other.cc b/libstdc++-v3/testsuite/27_io/ostream_inserter_other.cc
index 9d8cc0f..4ae1f3b 100644
--- a/libstdc++-v3/testsuite/27_io/ostream_inserter_other.cc
+++ b/libstdc++-v3/testsuite/27_io/ostream_inserter_other.cc
@@ -198,6 +198,28 @@ private:
std::string::const_iterator it;
};
+class test_buffer_4 : public std::streambuf {
+public:
+ test_buffer_4(const std::string& s) : str(s), it(str.begin())
+ {
+ if (it != str.end()) {
+ buf[0] = *it++;
+ setg(buf, buf, buf+1);
+ }
+ }
+
+protected:
+ virtual int underflow() { return (it != str.end() ? *it : EOF); }
+ virtual int uflow() { return (it != str.end() ? *it++ : EOF); }
+ virtual std::streamsize showmanyc() {
+ std::streamsize ret = std::distance(it, str.end());
+ return ret > 0 ? ret : -1;
+ }
+private:
+ const std::string str;
+ std::string::const_iterator it;
+ char buf[1];
+};
void test(const std::string& str, std::streambuf& buf)
{
@@ -218,8 +240,6 @@ void test(const std::string& str, std::streambuf& buf)
// Jonathan Lennox <lennox@cs.columbia.edu>
void test05()
{
- std::ostringstream out_1, out_2, out_3, out_4;
-
std::string string_a("Hello, world!");
std::string string_b("");
@@ -232,6 +252,9 @@ void test05()
test_buffer_3 buf3a(string_a);
test_buffer_3 buf3b(string_b);
+ test_buffer_4 buf4a(string_a);
+ test_buffer_4 buf4b(string_b);
+
test(string_a, buf1a);
test(string_b, buf1b);
@@ -240,6 +263,9 @@ void test05()
test(string_a, buf3a);
test(string_b, buf3b);
+
+ test(string_a, buf4a);
+ test(string_b, buf4b);
}
int