Author: marshall Date: Tue Sep 12 08:00:43 2017 New Revision: 313031 URL: http://llvm.org/viewvc/llvm-project?rev=313031&view=rev Log: Make pbump (internally) handle sizes bigger than MAX_INT. Fixes PR#33725 - thanks to Jonathan Wakely for the report
Added: libcxx/trunk/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp Modified: libcxx/trunk/include/fstream libcxx/trunk/include/locale libcxx/trunk/include/sstream libcxx/trunk/include/streambuf libcxx/trunk/src/strstream.cpp Modified: libcxx/trunk/include/fstream URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/fstream?rev=313031&r1=313030&r2=313031&view=diff ============================================================================== --- libcxx/trunk/include/fstream (original) +++ libcxx/trunk/include/fstream Tue Sep 12 08:00:43 2017 @@ -315,7 +315,7 @@ basic_filebuf<_CharT, _Traits>::basic_fi else this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase())); - this->pbump(__rhs. pptr() - __rhs.pbase()); + this->__pbump(__rhs. pptr() - __rhs.pbase()); } else if (__rhs.eback()) { @@ -434,7 +434,7 @@ basic_filebuf<_CharT, _Traits>::swap(bas ptrdiff_t __e = this->epptr() - this->pbase(); this->setp((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __e); - this->pbump(__n); + this->__pbump(__n); } if (__rhs.eback() == (char_type*)__extbuf_min_) { @@ -450,7 +450,7 @@ basic_filebuf<_CharT, _Traits>::swap(bas ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); __rhs.setp((char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __e); - __rhs.pbump(__n); + __rhs.__pbump(__n); } } @@ -724,7 +724,7 @@ basic_filebuf<_CharT, _Traits>::overflow if (__r == codecvt_base::partial) { this->setp(const_cast<char_type*>(__e), this->pptr()); - this->pbump(this->epptr() - this->pbase()); + this->__pbump(this->epptr() - this->pbase()); } } else Modified: libcxx/trunk/include/locale URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=313031&r1=313030&r2=313031&view=diff ============================================================================== --- libcxx/trunk/include/locale (original) +++ libcxx/trunk/include/locale Tue Sep 12 08:00:43 2017 @@ -4110,7 +4110,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::o if (__r == codecvt_base::partial) { this->setp(const_cast<char_type *>(__e), this->pptr()); - this->pbump(this->epptr() - this->pbase()); + this->__pbump(this->epptr() - this->pbase()); } } else Modified: libcxx/trunk/include/sstream URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/sstream?rev=313031&r1=313030&r2=313031&view=diff ============================================================================== --- libcxx/trunk/include/sstream (original) +++ libcxx/trunk/include/sstream Tue Sep 12 08:00:43 2017 @@ -289,7 +289,7 @@ basic_stringbuf<_CharT, _Traits, _Alloca if (__bout != -1) { this->setp(__p + __bout, __p + __eout); - this->pbump(__nout); + this->__pbump(__nout); } __hm_ = __hm == -1 ? nullptr : __p + __hm; __p = const_cast<char_type*>(__rhs.__str_.data()); @@ -332,7 +332,7 @@ basic_stringbuf<_CharT, _Traits, _Alloca if (__bout != -1) { this->setp(__p + __bout, __p + __eout); - this->pbump(__nout); + this->__pbump(__nout); } else this->setp(nullptr, nullptr); @@ -403,7 +403,7 @@ basic_stringbuf<_CharT, _Traits, _Alloca if (__rbout != -1) { this->setp(__p + __rbout, __p + __reout); - this->pbump(__rnout); + this->__pbump(__rnout); } else this->setp(nullptr, nullptr); @@ -416,7 +416,7 @@ basic_stringbuf<_CharT, _Traits, _Alloca if (__lbout != -1) { __rhs.setp(__p + __lbout, __p + __leout); - __rhs.pbump(__lnout); + __rhs.__pbump(__lnout); } else __rhs.setp(nullptr, nullptr); @@ -471,7 +471,15 @@ basic_stringbuf<_CharT, _Traits, _Alloca this->setp(const_cast<char_type*>(__str_.data()), const_cast<char_type*>(__str_.data()) + __str_.size()); if (__mode_ & (ios_base::app | ios_base::ate)) - this->pbump(__sz); + { + while (__sz > INT_MAX) + { + this->pbump(INT_MAX); + __sz -= INT_MAX; + } + if (__sz > 0) + this->pbump(__sz); + } } } @@ -536,7 +544,7 @@ basic_stringbuf<_CharT, _Traits, _Alloca __str_.resize(__str_.capacity()); char_type* __p = const_cast<char_type*>(__str_.data()); this->setp(__p, __p + __str_.size()); - this->pbump(__nout); + this->__pbump(__nout); __hm_ = this->pbase() + __hm; #ifndef _LIBCPP_NO_EXCEPTIONS } Modified: libcxx/trunk/include/streambuf URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/streambuf?rev=313031&r1=313030&r2=313031&view=diff ============================================================================== --- libcxx/trunk/include/streambuf (original) +++ libcxx/trunk/include/streambuf Tue Sep 12 08:00:43 2017 @@ -255,6 +255,9 @@ protected: inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY void pbump(int __n) { __nout_ += __n; } + _LIBCPP_ALWAYS_INLINE + void __pbump(streamsize __n) { __nout_ += __n; } + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY void setp(char_type* __pbeg, char_type* __pend) { __bout_ = __nout_ = __pbeg; Modified: libcxx/trunk/src/strstream.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/strstream.cpp?rev=313031&r1=313030&r2=313031&view=diff ============================================================================== --- libcxx/trunk/src/strstream.cpp (original) +++ libcxx/trunk/src/strstream.cpp Tue Sep 12 08:00:43 2017 @@ -186,7 +186,7 @@ strstreambuf::overflow(int_type __c) } setg(buf, buf + ninp, buf + einp); setp(buf + einp, buf + new_size); - pbump(static_cast<int>(nout)); + __pbump(nout); __strmode_ |= __allocated; } *pptr() = static_cast<char>(__c); @@ -282,7 +282,7 @@ strstreambuf::seekoff(off_type __off, io // min(pbase, newpos), newpos, epptr() __off = epptr() - newpos; setp(min(pbase(), newpos), epptr()); - pbump(static_cast<int>((epptr() - pbase()) - __off)); + __pbump((epptr() - pbase()) - __off); } __p = newoff; } @@ -312,7 +312,7 @@ strstreambuf::seekpos(pos_type __sp, ios // min(pbase, newpos), newpos, epptr() off_type temp = epptr() - newpos; setp(min(pbase(), newpos), epptr()); - pbump(static_cast<int>((epptr() - pbase()) - temp)); + __pbump((epptr() - pbase()) - temp); } __p = newoff; } Added: libcxx/trunk/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp?rev=313031&view=auto ============================================================================== --- libcxx/trunk/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp (added) +++ libcxx/trunk/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp Tue Sep 12 08:00:43 2017 @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <streambuf> + +// template <class charT, class traits = char_traits<charT> > +// class basic_streambuf; + +// void pbump(int n); + +#include <sstream> +#include <cassert> +#include "test_macros.h" + +struct SB : std::stringbuf +{ + SB() : std::stringbuf(std::ios::ate|std::ios::out) { } + const char* pubpbase() const { return pbase(); } + const char* pubpptr() const { return pptr(); } +}; + +int main() +{ +#ifndef TEST_HAS_NO_EXCEPTIONS + try { +#endif + std::string str(2147483648, 'a'); + SB sb; + sb.str(str); + assert(sb.pubpbase() <= sb.pubpptr()); +#ifndef TEST_HAS_NO_EXCEPTIONS + } + catch (const std::bad_alloc &) {} +#endif +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits