[libcxx] r275280 - Constuct a sentry object in istream::readsome, and handle failures appropriately. Fixes PR#28217.
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 13 09:58:48 PDT 2016
Author: marshall
Date: Wed Jul 13 11:58:48 2016
New Revision: 275280
URL: http://llvm.org/viewvc/llvm-project?rev=275280&view=rev
Log:
Constuct a sentry object in istream::readsome, and handle failures appropriately. Fixes PR#28217.
Modified:
libcxx/trunk/include/istream
Modified: libcxx/trunk/include/istream
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/istream?rev=275280&r1=275279&r2=275280&view=diff
==============================================================================
--- libcxx/trunk/include/istream (original)
+++ libcxx/trunk/include/istream Wed Jul 13 11:58:48 2016
@@ -1251,18 +1251,35 @@ streamsize
basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
{
__gc_ = 0;
- streamsize __c = this->rdbuf()->in_avail();
- switch (__c)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
- case -1:
- this->setstate(ios_base::eofbit);
- break;
- case 0:
- break;
- default:
- read(__s, _VSTD::min(__c, __n));
- break;
+#endif // _LIBCPP_NO_EXCEPTIONS
+ sentry __sen(*this, true);
+ if (__sen)
+ {
+ streamsize __c = this->rdbuf()->in_avail();
+ switch (__c)
+ {
+ case -1:
+ this->setstate(ios_base::eofbit);
+ break;
+ case 0:
+ break;
+ default:
+ read(__s, _VSTD::min(__c, __n));
+ break;
+ }
+ }
+ else
+ this->setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
}
+ catch (...)
+ {
+ this->__set_badbit_and_consider_rethrow();
+ }
+#endif // _LIBCPP_NO_EXCEPTIONS
return __gc_;
}
More information about the cfe-commits
mailing list