diff options
author | dim <dim@FreeBSD.org> | 2017-05-09 17:01:25 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2017-05-09 17:01:25 +0000 |
commit | 154d99cc3ac56f37bdf13dec1331ec90d9a0676f (patch) | |
tree | 003dfc0e67c397ef900c7d4e81961cc0360a25ed /contrib/libc++/include | |
parent | d1c5218b098101b458b1362327aa5dc754eefcf2 (diff) | |
download | FreeBSD-src-154d99cc3ac56f37bdf13dec1331ec90d9a0676f.zip FreeBSD-src-154d99cc3ac56f37bdf13dec1331ec90d9a0676f.tar.gz |
MFC r317888:
Pull in r302362 from upstream libc++ trunk (by me):
Ensure showbase does not overflow do_put buffers
Summary:
In https://bugs.freebsd.org/207918, Daniel McRobb describes how using
std::showbase with ostreams can cause truncation of unsigned long long
when output format is octal. In fact, this can even happen with
unsigned int and unsigned long.
To ensure this does not happen, add one additional character to the
do_put buffers if std::showbase is on. Also add a test case.
Reviewers: EricWF, mclow.lists
Reviewed By: EricWF
Subscribers: cfe-commits, emaste
Differential Revision: https://reviews.llvm.org/D32670
PR: 207918
Diffstat (limited to 'contrib/libc++/include')
-rw-r--r-- | contrib/libc++/include/locale | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/contrib/libc++/include/locale b/contrib/libc++/include/locale index 9cef429..d2d35ff 100644 --- a/contrib/libc++/include/locale +++ b/contrib/libc++/include/locale @@ -1399,6 +1399,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, this->__format_int(__fmt+1, __len, true, __iob.flags()); const unsigned __nbuf = (numeric_limits<long>::digits / 3) + ((numeric_limits<long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 2; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1425,6 +1426,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, this->__format_int(__fmt+1, __len, true, __iob.flags()); const unsigned __nbuf = (numeric_limits<long long>::digits / 3) + ((numeric_limits<long long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 2; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1451,6 +1453,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, this->__format_int(__fmt+1, __len, false, __iob.flags()); const unsigned __nbuf = (numeric_limits<unsigned long>::digits / 3) + ((numeric_limits<unsigned long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 1; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1477,6 +1480,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, this->__format_int(__fmt+1, __len, false, __iob.flags()); const unsigned __nbuf = (numeric_limits<unsigned long long>::digits / 3) + ((numeric_limits<unsigned long long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 1; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); |