summaryrefslogtreecommitdiffstats
path: root/libcxx/include/sstream
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2017-12-19 23:33:16 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2017-12-19 23:33:16 +0000
commit22c651c5770572641eaa16423b19e867f5f61d6b (patch)
treedd81257e2d9e5b0a97fd44be0a6bd7dce443644c /libcxx/include/sstream
parent7e13aef4281a275b8884bf14d1bdd6c7e0e9375c (diff)
downloadbcm5719-llvm-22c651c5770572641eaa16423b19e867f5f61d6b.tar.gz
bcm5719-llvm-22c651c5770572641eaa16423b19e867f5f61d6b.zip
libcxx: Fix for basic_stringbuf::seekoff() after r320604.
As a result of this change, the basic_stringbuf constructor that takes a mode ends up leaving __hm_ set to 0, causing the comparison "__hm_ - __str_.data() < __noff" in seekoff() to succeed, which caused the function to incorrectly return -1. The fix is to account for the possibility of __hm_ being 0 when computing the distance from __hm_ to the start of the string. Differential Revision: https://reviews.llvm.org/D41319 llvm-svn: 321124
Diffstat (limited to 'libcxx/include/sstream')
-rw-r--r--libcxx/include/sstream5
1 files changed, 3 insertions, 2 deletions
diff --git a/libcxx/include/sstream b/libcxx/include/sstream
index 34b0014c14a..b01f47b6872 100644
--- a/libcxx/include/sstream
+++ b/libcxx/include/sstream
@@ -577,6 +577,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off,
if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out)
&& __way == ios_base::cur)
return pos_type(-1);
+ const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data();
off_type __noff;
switch (__way)
{
@@ -590,13 +591,13 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off,
__noff = this->pptr() - this->pbase();
break;
case ios_base::end:
- __noff = __hm_ - __str_.data();
+ __noff = __hm;
break;
default:
return pos_type(-1);
}
__noff += __off;
- if (__noff < 0 || __hm_ - __str_.data() < __noff)
+ if (__noff < 0 || __hm < __noff)
return pos_type(-1);
if (__noff != 0)
{
OpenPOWER on IntegriCloud