-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
This happens when the absolute value is less than 1/10.
This is fine
char buffer[1024]{};
auto num = decimal32{ 1000000, -7 };
to_chars(std::begin(buffer), std::end(buffer), num, chars_format::fixed);This crashes in a memset() call
char buffer[1024]{};
auto num = decimal32{ 999999, -7 };
to_chars(std::begin(buffer), std::end(buffer), num, chars_format::fixed);The error is coming from "charconv.hpp". It's trying to memset() with a size of static_cast<std::size_t>(-1), inside the function detail::to_chars_fixed_impl().
else if (num_leading_zeros > precision)
{
*first++ = '0';
*first++ = '.';
std::memset(first, '0', static_cast<std::size_t>(precision));
return {first + precision, std::errc()};
}It looks like real_precision is defined at the top of the function but isn't used other than checking the buffer size. I'd hazard a guess that all uses of precision in this function should actually say real_precision.
Metadata
Metadata
Assignees
Labels
No labels