From c0b84d79d2533597dcce00eaddc0652aecf9fe87 Mon Sep 17 00:00:00 2001 From: Vadim Egorov Date: Tue, 9 May 2000 07:19:14 +0000 Subject: [PATCH] streambuf.tcc (basic_streambuf::xsgetn): Fix uflow case. 2000-05-09 Vadim Egorov Benjamin Kosnik Nathan Myers Dietmar Kuehl * bits/streambuf.tcc (basic_streambuf::xsgetn): Fix uflow case. (basic_streambuf::xsputn): Make consistent. * testsuite/27_io/filebuf.cc: Add tests. Co-Authored-By: Benjamin Kosnik Co-Authored-By: Dietmar Kuehl Co-Authored-By: Nathan Myers From-SVN: r33794 --- libstdc++-v3/ChangeLog | 9 +++++++++ libstdc++-v3/bits/streambuf.tcc | 18 ++++++++++-------- libstdc++-v3/testsuite/27_io/filebuf.cc | 21 ++++++++++++++++++++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5980f69..9bc1845 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2000-05-03 Vadim Egorov + Benjamin Kosnik + Nathan Myers + Dietmar Kuehl + + * bits/streambuf.tcc (basic_streambuf::xsgetn): Fix uflow case. + (basic_streambuf::xsputn): Make consistent. + * testsuite/27_io/filebuf.cc: Add tests. + 2000-05-08 Steven King * bits/char_traits.h: use wchar_t utility functions for diff --git a/libstdc++-v3/bits/streambuf.tcc b/libstdc++-v3/bits/streambuf.tcc index 8aeb421..45eb332 100644 --- a/libstdc++-v3/bits/streambuf.tcc +++ b/libstdc++-v3/bits/streambuf.tcc @@ -1,6 +1,6 @@ // Stream buffer classes -*- C++ -*- -// Copyright (C) 1997-1999 Free Software Foundation, Inc. +// Copyright (C) 1997-1999, 2000 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 @@ -145,10 +145,12 @@ namespace std { if (__retval != __n) { - if (this->uflow() != traits_type::eof()) - ++__retval; - else - break; + int_type __c = this->uflow(); + if (traits_type::eq_int_type(__c, traits_type::eof())) + break; + + traits_type::assign(*__s++, traits_type::to_char_type(__c)); + ++__retval; } } } @@ -175,9 +177,9 @@ namespace std { bool __testout = _M_mode & ios_base::out; if (!(__testput && __testout)) { - char_type __c = *__s; - char_type __overfc = this->overflow(__c); - if (__c == __overfc) + int_type __c = traits_type::to_int_type(*__s); + int_type __overfc = this->overflow(__c); + if (traits_type::eq_int_type(__c, __overfc)) { ++__retval; ++__s; diff --git a/libstdc++-v3/testsuite/27_io/filebuf.cc b/libstdc++-v3/testsuite/27_io/filebuf.cc index 586388e..40e6cc6 100644 --- a/libstdc++-v3/testsuite/27_io/filebuf.cc +++ b/libstdc++-v3/testsuite/27_io/filebuf.cc @@ -503,12 +503,31 @@ bool test03() { return test; } +bool test04() +{ + using namespace std; + typedef istream::int_type int_type; + + bool test = true; + ifstream ifs(name_02); + char buffer[] = "xxxxxxxxxx"; + int_type len1 = ifs.rdbuf()->sgetn(buffer, sizeof(buffer)); + test &= len1 == sizeof(buffer); + test &= buffer[0] == 'a'; -int main() { +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ test00(); test01(); test02(); test03(); + test04(); return 0; } -- 2.7.4