| ... | @@ -821,6 +821,14 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits> | ... | @@ -821,6 +821,14 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits> |
| 821 | | 821 | |
| 822 | template <class _CharT, class _Traits> | 822 | template <class _CharT, class _Traits> |
| 823 | typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) { | 823 | typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) { |
| | 824 | auto __failed = [this]() { |
| | 825 | if (this->pptr() == this->epptr() + 1) { |
| | 826 | this->pbump(-1); // lose the character we overflowed above -- we don't really have a |
| | 827 | // choice since we couldn't commit the contents of the put area |
| | 828 | } |
| | 829 | return traits_type::eof(); |
| | 830 | }; |
| | 831 | |
| 824 | if (__file_ == nullptr) | 832 | if (__file_ == nullptr) |
| 825 | return traits_type::eof(); | 833 | return traits_type::eof(); |
| 826 | __write_mode(); | 834 | __write_mode(); |
| ... | @@ -841,8 +849,9 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits> | ... | @@ -841,8 +849,9 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits> |
| 841 | | 849 | |
| 842 | if (__always_noconv_) { | 850 | if (__always_noconv_) { |
| 843 | size_t __n = static_cast<size_t>(this->pptr() - this->pbase()); | 851 | size_t __n = static_cast<size_t>(this->pptr() - this->pbase()); |
| 844 | if (std::fwrite(this->pbase(), sizeof(char_type), __n, __file_) != __n) | 852 | if (std::fwrite(this->pbase(), sizeof(char_type), __n, __file_) != __n) { |
| 845 | return traits_type::eof(); | 853 | return __failed(); |
| | 854 | } |
| 846 | } else { | 855 | } else { |
| 847 | if (!__cv_) | 856 | if (!__cv_) |
| 848 | std::__throw_bad_cast(); | 857 | std::__throw_bad_cast(); |
| ... | @@ -854,34 +863,38 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits> | ... | @@ -854,34 +863,38 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits> |
| 854 | char* __extbuf_end = __extbuf_; | 863 | char* __extbuf_end = __extbuf_; |
| 855 | do { | 864 | do { |
| 856 | codecvt_base::result __r = __cv_->out(__st_, __b, __p, __end, __extbuf_, __extbuf_ + __ebs_, __extbuf_end); | 865 | codecvt_base::result __r = __cv_->out(__st_, __b, __p, __end, __extbuf_, __extbuf_ + __ebs_, __extbuf_end); |
| 857 | if (__end == __b) | 866 | if (__end == __b) { |
| 858 | return traits_type::eof(); | 867 | return __failed(); |
| | 868 | } |
| 859 | | 869 | |
| 860 | // No conversion needed: output characters directly to the file, done. | 870 | // No conversion needed: output characters directly to the file, done. |
| 861 | if (__r == codecvt_base::noconv) { | 871 | if (__r == codecvt_base::noconv) { |
| 862 | size_t __n = static_cast<size_t>(__p - __b); | 872 | size_t __n = static_cast<size_t>(__p - __b); |
| 863 | if (std::fwrite(__b, 1, __n, __file_) != __n) | 873 | if (std::fwrite(__b, 1, __n, __file_) != __n) { |
| 864 | return traits_type::eof(); | 874 | return __failed(); |
| | 875 | } |
| 865 | break; | 876 | break; |
| 866 | | 877 | |
| 867 | // Conversion successful: output the converted characters to the file, done. | 878 | // Conversion successful: output the converted characters to the file, done. |
| 868 | } else if (__r == codecvt_base::ok) { | 879 | } else if (__r == codecvt_base::ok) { |
| 869 | size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_); | 880 | size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_); |
| 870 | if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) | 881 | if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) { |
| 871 | return traits_type::eof(); | 882 | return __failed(); |
| | 883 | } |
| 872 | break; | 884 | break; |
| 873 | | 885 | |
| 874 | // Conversion partially successful: output converted characters to the file and repeat with the | 886 | // Conversion partially successful: output converted characters to the file and repeat with the |
| 875 | // remaining characters. | 887 | // remaining characters. |
| 876 | } else if (__r == codecvt_base::partial) { | 888 | } else if (__r == codecvt_base::partial) { |
| 877 | size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_); | 889 | size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_); |
| 878 | if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) | 890 | if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) { |
| 879 | return traits_type::eof(); | 891 | return __failed(); |
| | 892 | } |
| 880 | __b = const_cast<char_type*>(__end); | 893 | __b = const_cast<char_type*>(__end); |
| 881 | continue; | 894 | continue; |
| 882 | | 895 | |
| 883 | } else { | 896 | } else { |
| 884 | return traits_type::eof(); | 897 | return __failed(); |
| 885 | } | 898 | } |
| 886 | } while (true); | 899 | } while (true); |
| 887 | } | 900 | } |