aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/ostream.tcc
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/include/bits/ostream.tcc')
-rw-r--r--libstdc++-v3/include/bits/ostream.tcc73
1 files changed, 38 insertions, 35 deletions
diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc
index 91c1b124805..e42eca29192 100644
--- a/libstdc++-v3/include/bits/ostream.tcc
+++ b/libstdc++-v3/include/bits/ostream.tcc
@@ -119,19 +119,11 @@ namespace std
basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
{
sentry __cerb(*this);
- if (__cerb)
+ if (__cerb && __sbin)
{
try
{
- streamsize __xtrct = 0;
- if (__sbin)
- {
- __streambuf_type* __sbout = this->rdbuf();
- __xtrct = __copy_streambufs(*this, __sbin, __sbout);
- }
- else
- this->setstate(ios_base::badbit);
- if (!__xtrct)
+ if (!__copy_streambufs(*this, __sbin, this->rdbuf()))
this->setstate(ios_base::failbit);
}
catch(exception& __fail)
@@ -143,6 +135,8 @@ namespace std
__throw_exception_again;
}
}
+ else if (!__sbin)
+ this->setstate(ios_base::badbit);
return *this;
}
@@ -185,7 +179,7 @@ namespace std
if (_M_check_facet(_M_fnumput))
{
bool __b = false;
- if (__fmt & ios_base::oct || __fmt & ios_base::hex)
+ if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
{
unsigned long __l = static_cast<unsigned long>(__n);
__b = _M_fnumput->put(*this, *this, __c, __l).failed();
@@ -248,7 +242,7 @@ namespace std
if (_M_check_facet(_M_fnumput))
{
bool __b = false;
- if (__fmt & ios_base::oct || __fmt & ios_base::hex)
+ if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
{
unsigned long long __l;
__l = static_cast<unsigned long long>(__n);
@@ -419,9 +413,7 @@ namespace std
basic_ostream<_CharT, _Traits>::tellp()
{
pos_type __ret = pos_type(-1);
- bool __testok = this->fail() != true;
-
- if (__testok)
+ if (!this->fail())
__ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
return __ret;
}
@@ -431,9 +423,7 @@ namespace std
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
{
- bool __testok = this->fail() != true;
-
- if (__testok)
+ if (!this->fail())
{
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 136. seekp, seekg setting wrong streams?
@@ -452,9 +442,7 @@ namespace std
basic_ostream<_CharT, _Traits>::
seekp(off_type __off, ios_base::seekdir __d)
{
- bool __testok = this->fail() != true;
-
- if (__testok)
+ if (!this->fail())
{
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 136. seekp, seekg setting wrong streams?
@@ -464,8 +452,8 @@ namespace std
// 129. Need error indication from seekp() and seekg()
if (__err == pos_type(off_type(-1)))
this->setstate(ios_base::failbit);
- }
#endif
+ }
return *this;
}
@@ -481,12 +469,13 @@ namespace std
try
{
streamsize __w = __out.width();
- _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
+ _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__w + 1)));
__pads[0] = __c;
streamsize __len = 1;
if (__w > __len)
{
- __pad(__out, __out.fill(), __pads, &__c, __w, __len, false);
+ __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads,
+ &__c, __w, __len, false);
__len = __w;
}
__out.write(__pads, __len);
@@ -521,7 +510,8 @@ namespace std
streamsize __len = 1;
if (__w > __len)
{
- __pad(__out, __out.fill(), __pads, &__c, __w, __len, false);
+ __pad<char, _Traits>::_S_pad(__out, __out.fill(), __pads,
+ &__c, __w, __len, false);
__len = __w;
}
__out.write(__pads, __len);
@@ -545,7 +535,7 @@ namespace std
{
typedef basic_ostream<_CharT, _Traits> __ostream_type;
typename __ostream_type::sentry __cerb(__out);
- if (__cerb)
+ if (__cerb && __s)
{
try
{
@@ -554,7 +544,8 @@ namespace std
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len)
{
- __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
+ __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads,
+ __s, __w, __len, false);
__s = __pads;
__len = __w;
}
@@ -570,6 +561,8 @@ namespace std
__throw_exception_again;
}
}
+ else if (!__s)
+ __out.setstate(ios_base::badbit);
return __out;
}
@@ -581,14 +574,14 @@ namespace std
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 167. Improper use of traits_type::length()
// Note that this is only in 'Review' status.
- typedef char_traits<char> __ctraits_type;
+ typedef char_traits<char> __traits_type;
#endif
typename __ostream_type::sentry __cerb(__out);
- if (__cerb)
+ if (__cerb && __s)
{
- size_t __clen = __ctraits_type::length(__s);
+ size_t __clen = __traits_type::length(__s);
_CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
- for (size_t __i = 0; __i <= __clen; ++__i)
+ for (size_t __i = 0; __i < __clen; ++__i)
__ws[__i] = __out.widen(__s[__i]);
_CharT* __str = __ws;
@@ -600,7 +593,8 @@ namespace std
if (__w > __len)
{
- __pad(__out, __out.fill(), __pads, __ws, __w, __len, false);
+ __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads,
+ __ws, __w, __len, false);
__str = __pads;
__len = __w;
}
@@ -616,6 +610,8 @@ namespace std
__throw_exception_again;
}
}
+ else if (!__s)
+ __out.setstate(ios_base::badbit);
return __out;
}
@@ -626,16 +622,18 @@ namespace std
{
typedef basic_ostream<char, _Traits> __ostream_type;
typename __ostream_type::sentry __cerb(__out);
- if (__cerb)
+ if (__cerb && __s)
{
try
{
streamsize __w = __out.width();
char* __pads = static_cast<char*>(__builtin_alloca(__w));
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
+
if (__w > __len)
{
- __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
+ __pad<char, _Traits>::_S_pad(__out, __out.fill(), __pads,
+ __s, __w, __len, false);
__s = __pads;
__len = __w;
}
@@ -651,6 +649,8 @@ namespace std
__throw_exception_again;
}
}
+ else if (!__s)
+ __out.setstate(ios_base::badbit);
return __out;
}
@@ -673,7 +673,8 @@ namespace std
#endif
if (__w > __len)
{
- __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
+ __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, __s,
+ __w, __len, false);
__s = __pads;
__len = __w;
}
@@ -699,6 +700,7 @@ namespace std
extern template ostream& operator<<(ostream&, const unsigned char*);
extern template ostream& operator<<(ostream&, const signed char*);
+#ifdef _GLIBCPP_USE_WCHAR_T
extern template class basic_ostream<wchar_t>;
extern template wostream& endl(wostream&);
extern template wostream& ends(wostream&);
@@ -707,4 +709,5 @@ namespace std
extern template wostream& operator<<(wostream&, char);
extern template wostream& operator<<(wostream&, const wchar_t*);
extern template wostream& operator<<(wostream&, const char*);
+#endif
} // namespace std