Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 May 2017 21:43:55 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r317888 - head/contrib/libc++/include
Message-ID:  <201705062143.v46Lhtv2068534@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Sat May  6 21:43:55 2017
New Revision: 317888
URL: https://svnweb.freebsd.org/changeset/base/317888

Log:
  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
  MFC after:	3 days

Modified:
  head/contrib/libc++/include/locale

Modified: head/contrib/libc++/include/locale
==============================================================================
--- head/contrib/libc++/include/locale	Sat May  6 20:32:27 2017	(r317887)
+++ head/contrib/libc++/include/locale	Sat May  6 21:43:55 2017	(r317888)
@@ -1399,6 +1399,7 @@ num_put<_CharT, _OutputIterator>::do_put
     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
     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
     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
     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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705062143.v46Lhtv2068534>