Re: [Boost-bugs] [Boost C++ Libraries] #5983: Stack overflow with Karma floating point generator

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5983: Stack overflow with Karma floating point generator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-05-04 13:29:31


#5983: Stack overflow with Karma floating point generator
--------------------------------------+----------------------------------
  Reporter: matt.chambers42@… | Owner: hkaiser
      Type: Bugs | Status: assigned
 Milestone: To Be Determined | Component: spirit
   Version: Boost Development Trunk | Severity: Problem
Resolution: | Keywords: karma stack overflow
--------------------------------------+----------------------------------

Comment (by Daniel Krügler <daniel.kruegler@…>):

 I stumbled across the same issue yesterday using boost 1.55, that is the
 missing support for denormalized numbers by karma::generate. This is a
 very nasty bug for us and it basically forbids is to use karma::generate
 for floating point numbers in our source code, which is really unfortunate
 due to the otherwise excellent properties of this function and the
 library.

 Since I'm seeing no progress on this bug since three years I would like to
 help solving it.

 First, here is a more specific test-case:

 {{{
 #include <limits>
 #include <stdexcept>
 #include <iostream>
 #include <string>

 #include "boost/spirit/include/karma.hpp"

 template <class T>
 std::string to_string(const T& value)
 {
   std::string res;
   if (!boost::spirit::karma::generate(std::back_inserter(res), value))
     throw std::invalid_argument("Could not convert argument to string");
   return res;
 }

 int main() {
   try {
     std::string s = to_string(std::numeric_limits<double>::denorm_min());
     std::cout << s << std::endl;
   } catch (...) {
     std::cout << "Error!" << std::endl;
   }
 }
 }}}

 which crashes due to an assertion failure in
 "boost/spirit/home/support/detail/pow10.hpp", line 87. The error is
 understandable, because boost::spirit::traits::pow10 can only handle
 positive dimensions and it is impossible to map the (negative) exponent of
 a denormalized number to an exponential value in the domain of the
 corresponding type by a single multiplication.

 Second, I have created an patch file against the recent boost SVN head.
 Please consider to apply the attached file real_utils.diff.

 If you have any further questions or requirements for a patch, please let
 me know.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5983#comment:2>
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:16 UTC