-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialized value not always can be parsed. #329
Comments
I think the underlying problem is the following: The code json j = json::parse("22e2222");
std::cerr << j << std::endl; outputs This contradicts the paragraph
from the documentation. It seems as if at some point, the overflow is not detected. |
For floating-point numbers, the constructor looks like this: basic_json(const number_float_t val) noexcept
: m_type(value_t::number_float), m_value(val)
{
// replace infinity and NAN by null
if (not std::isfinite(val))
{
m_type = value_t::null;
m_value = json_value();
}
assert_invariant();
} The replacement of infinity/NAN by I am currently torn how to cope with numbers that exceed the limits of
The question is how to deal with numbers that do not fit to double precision. "set limits on the range and numbers accepted" could be interpreted that numbers outside this range should be rejected which would mean throwing an exception when such a number is encountered. What do you think? |
Throwing an exception sounds like a reasonable thing to do. |
+1 for exception |
I think an exception is the way to go (both in the constructor and in the parser). I shall implement this change in the 3.0.0 release as it changes the public API. |
- If an overflow occurs during parsing a number from a JSON text, an exception (std::out_of_range for the moment, to be replaced by a user-defined exception #244) is thrown so that the overflow is detected early and roundtripping is guaranteed. - NaN and INF floating-point values can be stored in a JSON value and are not replaced by null. That is, the basic_json class behaves like double in this regard (no exception occurs). However, NaN and INF are serialized to “null”. - Adjusted test cases appropriately.
This issue is fixed with 8feaf8d as follows:
Waiting for Travis to complete. Then this issue can be closed and the different semantics can be described in the wiki. |
Since #329, NaN and inf numbers do not yield an exception, but are stored internally and are dumped as “null”. This commit adjusts the fuzz testers to deal with this special case.
I assume that if value was parsed without exception it should be serializable and parsables again.
The text was updated successfully, but these errors were encountered: