summaryrefslogtreecommitdiffstats
path: root/libcxx/include
diff options
context:
space:
mode:
authorVolodymyr Sapsai <vsapsai@apple.com>2018-01-11 23:23:49 +0000
committerVolodymyr Sapsai <vsapsai@apple.com>2018-01-11 23:23:49 +0000
commita051024cacfaab5b307c2df9e9e7ab4ff121d193 (patch)
treefad935abee1adddeef1202d528a535f2d7d606fe /libcxx/include
parentbfd9c4a4626c4b2739f33d628f43778beb59299d (diff)
downloadbcm5719-llvm-a051024cacfaab5b307c2df9e9e7ab4ff121d193.tar.gz
bcm5719-llvm-a051024cacfaab5b307c2df9e9e7ab4ff121d193.zip
[libcxx] Make std::basic_istream::get 0-terminate input array in case of error.
It covers the cases when the sentry object returns false and when an exception was thrown. Corresponding standard paragraph is C++14 [istream.unformatted]p9: [...] In any case, if n is greater than zero it then stores a null character into the next successive location of the array. rdar://problem/35566567 Reviewers: EricWF, mclow.lists Reviewed By: mclow.lists Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40677 llvm-svn: 322326
Diffstat (limited to 'libcxx/include')
-rw-r--r--libcxx/include/istream5
1 files changed, 4 insertions, 1 deletions
diff --git a/libcxx/include/istream b/libcxx/include/istream
index 5c73df38f65..f2579c14d82 100644
--- a/libcxx/include/istream
+++ b/libcxx/include/istream
@@ -960,7 +960,6 @@ basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __
++__gc_;
this->rdbuf()->sbumpc();
}
- *__s = char_type();
if (__gc_ == 0)
__err |= ios_base::failbit;
this->setstate(__err);
@@ -968,10 +967,14 @@ basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __
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
OpenPOWER on IntegriCloud