Skip to content

Commit

Permalink
Fix overflow warning in print_helper.hpp. #398 (#399)
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'.

Co-authored-by: Matt Borland <[email protected]>
  • Loading branch information
JBouwer and mborland authored Jan 9, 2024
1 parent 8b078be commit e0d9c9f
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 e0d9c9f

Please sign in to comment.