Skip to content

Commit

Permalink
Fix overflow warning in print_helper.hpp. #398
Browse files Browse the repository at this point in the history
- (Implicitly) printing a big enough type results in:
  "warning: overflow in expression; result is 2147483347 with type 'int' [-Winteger-overflow]".
- Fixed by promoting the calculation to 'std::streamsize'.
  • Loading branch information
JBouwer committed Nov 13, 2023
1 parent a606369 commit 71800b5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/boost/test/tools/detail/print_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct print_log_value {
std::streamsize set_precision( std::ostream& ostr, mpl::false_ )
{
if( std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::radix == 2 )
return ostr.precision( 2 + std::numeric_limits<T>::digits * 301/1000 );
return ostr.precision( 2 + std::streamsize(std::numeric_limits<T>::digits) * 301/1000 );
else if ( std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::radix == 10 ) {
#ifdef BOOST_NO_CXX11_NUMERIC_LIMITS
// (was BOOST_NO_NUMERIC_LIMITS_LOWEST but now deprecated).
Expand Down

0 comments on commit 71800b5

Please sign in to comment.