Skip to content

Commit f622f48

Browse files
committed
Suppress GCC-12+ warning of too big a memset
1 parent 49ba4bb commit f622f48

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

include/boost/decimal/charconv.hpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,28 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_fixed_impl(char* first, char* last, const
586586
// We can skip the rest if there's nothing more to do for the required precision
587587
if (significand == 0)
588588
{
589-
std::memset(first, '0', static_cast<std::size_t>(precision - num_leading_zeros));
590-
return {first + precision, std::errc()};
589+
if (precision - num_leading_zeros > 0)
590+
{
591+
#if defined(__GNUC__) && __GNUC__ >= 12
592+
#pragma GCC diagnostic push
593+
#pragma GCC diagnostic ignored "-Warray-bounds"
594+
#endif
595+
596+
// We have already done the check to make sure that casting this to size_t does not cause
597+
// unsigned rollover so we ignore GCC-12+ warning us about using memset on a huge number
598+
// We have also previously checked the buffer size
599+
std::memset(first, '0', static_cast<std::size_t>(precision - num_leading_zeros));
600+
601+
#if defined(__GNUC__) && __GNUC__ >= 12
602+
#pragma GCC diagnostic pop
603+
#endif
604+
605+
return {first + precision, std::errc()};
606+
}
607+
else
608+
{
609+
return {first, std::errc()};
610+
}
591611
}
592612
}
593613
}

0 commit comments

Comments
 (0)