[Boost-bugs] [Boost C++ Libraries] #11669: lexical_cast crashes on certain conditions for floating point types

Subject: [Boost-bugs] [Boost C++ Libraries] #11669: lexical_cast crashes on certain conditions for floating point types
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-09-18 18:45:30


#11669: lexical_cast crashes on certain conditions for floating point types
--------------------------------+--------------------------
 Reporter: alday.boost.trac@… | Owner: apolukhin
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: lexical_cast
  Version: Boost 1.59.0 | Severity: Problem
 Keywords: |
--------------------------------+--------------------------
 In the presence of BOOST_LCAST_NO_COMPILE_TIME_PRECISION, there is no
 specialization of lcast_src_length<Source> for floating types, so
 lexical_converter_impl will allocate only 2 bytes and then try to do a
 sprintf, making the program crash.

 While the specialization for integral types checks for the presence of
 BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS, and ifdefs an arbitrary value or
 one calculated via std::numeric_limits, the specialization for floats gets
 wiped out completely in the presence of
 BOOST_LCAST_NO_COMPILE_TIME_PRECISION.

 Could you please do for floats what you do for integrals? I attach a patch
 that assigns an (arbitrary) max length of 156 to the representation of
 floats.

 Basically, instead of
 {{{
 #ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
 template<class Source>
         struct lcast_src_length<Source, BOOST_DEDUCED_TYPENAME
 boost::enable_if<boost::is_float<Source> >::type>
         {
 ...
             BOOST_STATIC_CONSTANT(std::size_t, value =5 +
 lcast_precision<Source>::value + 6);
         };
 #endif // #ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
 }}}

 I'd like to move the ifndef inside, as in
 {{{
  template<class Source>
         struct lcast_src_length<Source, BOOST_DEDUCED_TYPENAME
 boost::enable_if<boost::is_float<Source> >::type>
         {
 #ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
 ...
             BOOST_STATIC_CONSTANT(std::size_t, value =5 +
 lcast_precision<Source>::value + 6);
 #else
             BOOST_STATIC_CONSTANT(std::size_t, value = 156);
 #ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
 }}}

 The easiest way to reproduce it is:
 {{{
 #include <string>
 #define BOOST_LCAST_NO_COMPILE_TIME_PRECISION
 #include <boost/lexical_cast.hpp>
 int main() {
         boost::lexical_cast<std::string>(2.12345);
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11669>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC