Index: libcxx/trunk/include/istream =================================================================== --- libcxx/trunk/include/istream +++ libcxx/trunk/include/istream @@ -960,7 +960,6 @@ ++__gc_; this->rdbuf()->sbumpc(); } - *__s = char_type(); if (__gc_ == 0) __err |= ios_base::failbit; this->setstate(__err); @@ -968,10 +967,14 @@ else this->setstate(ios_base::failbit); } + if (__n > 0) + *__s = char_type(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { + if (__n > 0) + *__s = char_type(); this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS Index: libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp =================================================================== --- libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp +++ libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp @@ -7,6 +7,14 @@ // //===----------------------------------------------------------------------===// +// XFAIL: with_system_cxx_lib=macosx10.13 +// XFAIL: with_system_cxx_lib=macosx10.12 +// XFAIL: with_system_cxx_lib=macosx10.11 +// XFAIL: with_system_cxx_lib=macosx10.10 +// XFAIL: with_system_cxx_lib=macosx10.9 +// XFAIL: with_system_cxx_lib=macosx10.8 +// XFAIL: with_system_cxx_lib=macosx10.7 + // // basic_istream& get(char_type* s, streamsize n); @@ -14,6 +22,8 @@ #include #include +#include "test_macros.h" + template struct testbuf : public std::basic_streambuf @@ -67,7 +77,33 @@ assert(!is.fail()); assert(std::string(s) == " "); assert(is.gcount() == 1); + // Check that even in error case the buffer is properly 0-terminated. + is.get(s, 5); + assert( is.eof()); + assert( is.fail()); + assert(std::string(s) == ""); + assert(is.gcount() == 0); + } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf sb(" "); + std::istream is(&sb); + char s[5] = "test"; + is.exceptions(std::istream::eofbit | std::istream::badbit); + try + { + is.get(s, 5); + assert(false); + } + catch (std::ios_base::failure&) + { + } + assert( is.eof()); + assert( is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 1); } +#endif { testbuf sb(L" \n \n "); std::wistream is(&sb); @@ -95,5 +131,31 @@ assert(!is.fail()); assert(std::wstring(s) == L" "); assert(is.gcount() == 1); + // Check that even in error case the buffer is properly 0-terminated. + is.get(s, 5); + assert( is.eof()); + assert( is.fail()); + assert(std::wstring(s) == L""); + assert(is.gcount() == 0); + } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf sb(L" "); + std::wistream is(&sb); + wchar_t s[5] = L"test"; + is.exceptions(std::wistream::eofbit | std::wistream::badbit); + try + { + is.get(s, 5); + assert(false); + } + catch (std::ios_base::failure&) + { + } + assert( is.eof()); + assert( is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 1); } +#endif } Index: libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp =================================================================== --- libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp +++ libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp @@ -7,6 +7,14 @@ // //===----------------------------------------------------------------------===// +// XFAIL: with_system_cxx_lib=macosx10.13 +// XFAIL: with_system_cxx_lib=macosx10.12 +// XFAIL: with_system_cxx_lib=macosx10.11 +// XFAIL: with_system_cxx_lib=macosx10.10 +// XFAIL: with_system_cxx_lib=macosx10.9 +// XFAIL: with_system_cxx_lib=macosx10.8 +// XFAIL: with_system_cxx_lib=macosx10.7 + // // basic_istream& get(char_type* s, streamsize n, char_type delim); @@ -14,6 +22,8 @@ #include #include +#include "test_macros.h" + template struct testbuf : public std::basic_streambuf @@ -67,7 +77,33 @@ assert(!is.fail()); assert(std::string(s) == " "); assert(is.gcount() == 1); + // Check that even in error case the buffer is properly 0-terminated. + is.get(s, 5, '*'); + assert( is.eof()); + assert( is.fail()); + assert(std::string(s) == ""); + assert(is.gcount() == 0); + } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf sb(" "); + std::istream is(&sb); + char s[5] = "test"; + is.exceptions(std::istream::eofbit | std::istream::badbit); + try + { + is.get(s, 5, '*'); + assert(false); + } + catch (std::ios_base::failure&) + { + } + assert( is.eof()); + assert( is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 1); } +#endif { testbuf sb(L" * * "); std::wistream is(&sb); @@ -95,5 +131,31 @@ assert(!is.fail()); assert(std::wstring(s) == L" "); assert(is.gcount() == 1); + // Check that even in error case the buffer is properly 0-terminated. + is.get(s, 5, L'*'); + assert( is.eof()); + assert( is.fail()); + assert(std::wstring(s) == L""); + assert(is.gcount() == 0); + } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf sb(L" "); + std::wistream is(&sb); + wchar_t s[5] = L"test"; + is.exceptions(std::wistream::eofbit | std::wistream::badbit); + try + { + is.get(s, 5, L'*'); + assert(false); + } + catch (std::ios_base::failure&) + { + } + assert( is.eof()); + assert( is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 1); } +#endif }