This commit is contained in:
deeaitch committed 2026-10-14 10:41:17 -04:00
1 parent d87c100398
commit 4ae4e527b8
5 files changed
+138 -10

No files matched your search

+12 -8
View File
@@ -35,14 +35,18 @@ namespace {
R"(^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$)");
if (!std::regex_match(text, number))
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
std::size_t consumed = 0U;
double value;
try {
value = std::stod(text, &consumed);
} catch (const std::exception &) {
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
}
if (consumed != text.size() || !std::isfinite(value))
// Floating-point from_chars is locale-independent and does not accept
// a leading '+', which the DBC numeric grammar permits.
const char *begin = text.data();
const char *end = begin + text.size();
if (*begin == '+')
++begin;
double value = 0.0;
const std::from_chars_result parsed =
std::from_chars(begin, end, value, std::chars_format::general);
// Keep the existing rejection of conversion underflow into subnormal values.
if (parsed.ec != std::errc() || parsed.ptr != end || !std::isfinite(value) ||
std::fpclassify(value) == FP_SUBNORMAL)
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
return value;
}