Skip to content

Commit 5c6a236

Browse files
committed
Fix non-finite values being over-written
1 parent f05d650 commit 5c6a236

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

include/boost/decimal/charconv.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,23 @@ constexpr auto from_chars_general_impl(const char* first, const char* last, Targ
104104
errno = static_cast<int>(r.ec);
105105
}
106106
}
107-
108-
BOOST_DECIMAL_IF_CONSTEXPR (!is_fast_type_v<TargetDecimalType>)
107+
else
109108
{
110-
if (fmt == chars_format::cohort_preserving_scientific)
109+
BOOST_DECIMAL_IF_CONSTEXPR (!is_fast_type_v<TargetDecimalType>)
111110
{
112-
const auto sig_digs {detail::num_digits(significand)};
113-
if (sig_digs > precision_v<TargetDecimalType>)
111+
if (fmt == chars_format::cohort_preserving_scientific)
114112
{
115-
// If we are parsing more digits than are representable there's no concept of cohorts
116-
return {last, std::errc::value_too_large};
113+
const auto sig_digs {detail::num_digits(significand)};
114+
if (sig_digs > precision_v<TargetDecimalType>)
115+
{
116+
// If we are parsing more digits than are representable there's no concept of cohorts
117+
return {last, std::errc::value_too_large};
118+
}
117119
}
118120
}
119-
}
120121

121-
value = TargetDecimalType(significand, expval, sign);
122+
value = TargetDecimalType(significand, expval, sign);
123+
}
122124

123125
return r;
124126
}

0 commit comments

Comments
 (0)