Subject: Re: [Boost-bugs] [Boost C++ Libraries] #10109: Wrong overflow checking with uint_parser<int>
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-06-10 16:59:16
#10109: Wrong overflow checking with uint_parser<int>
----------------------------------------------+---------------------
Reporter: Giulio Franco <giulio_franco@â¦> | Owner: djowel
Type: Bugs | Status: new
Milestone: To Be Determined | Component: spirit
Version: Boost Release Branch | Severity: Problem
Resolution: | Keywords:
----------------------------------------------+---------------------
Comment (by Giulio Franco <giulio_franco@â¦>):
According to the docs, `uint_parser` is supposed to parse an unsigned
value, it doesn't make any restriction on the type it will read the value
into. In fact, you can also create a uint_parser<double>, and in that case
`int_extractor::call(Char, size_t, T&)` will use a different
implementation, that just adds the digits without checking for overflow.
As I wrote, the current implementations already checks for wrap around, by
using `std::numeric_limits<T>::max` in
{{{
#!c++
template<typename T, typename Char>
positive_accumulator::add(T&, Char, mpl::true_)
}}}
The only issue is that it's using the wrong `T`. It uses
`numeric_limits<unsigned int>`, because it is passed an `unsigned int&`.
If it used `numeric_limits<signed int>` with the very same algorithm it
would probably work perfectly.
It looks like it only involves template work, which means no performance
impact for those who aren't using it.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/10109#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