Skip to content

Commit

Permalink
Suppress GCC-12+ warning of too big a memset
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Jan 18, 2025
1 parent 49ba4bb commit f622f48
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions include/boost/decimal/charconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,28 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_fixed_impl(char* first, char* last, const
// We can skip the rest if there's nothing more to do for the required precision
if (significand == 0)
{
std::memset(first, '0', static_cast<std::size_t>(precision - num_leading_zeros));
return {first + precision, std::errc()};
if (precision - num_leading_zeros > 0)
{
#if defined(__GNUC__) && __GNUC__ >= 12
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif

// We have already done the check to make sure that casting this to size_t does not cause
// unsigned rollover so we ignore GCC-12+ warning us about using memset on a huge number
// We have also previously checked the buffer size
std::memset(first, '0', static_cast<std::size_t>(precision - num_leading_zeros));

#if defined(__GNUC__) && __GNUC__ >= 12
#pragma GCC diagnostic pop
#endif

return {first + precision, std::errc()};
}
else
{
return {first, std::errc()};
}
}
}
}
Expand Down

0 comments on commit f622f48

Please sign in to comment.