Skip to content
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

Sometimes a double value is not serialized #509

Closed
Ekmansoft opened this issue Nov 20, 2019 · 14 comments
Closed

Sometimes a double value is not serialized #509

Ekmansoft opened this issue Nov 20, 2019 · 14 comments

Comments

@Ekmansoft
Copy link

We have seen twice now error messages where json-c has failed parsing a json file written by the same app (and thus json-c). In both cases the files got invalid syntax, as one double value had not been serialized, like the missing width value in the example below.

.... “size”: { “width”: , “height”: 0.5 }, ....

It happens very seldom, and was detected by automated testing in both cases.

@hawicz
Copy link
Member

hawicz commented Nov 21, 2019

Can you provide any other details? It's going to be pretty hard to do anything with this bug report without a reproducible test case, or at least some kind of description of what might be unique in the situation where you've noticed a problem.

@Ekmansoft
Copy link
Author

Ekmansoft commented Nov 21, 2019 via email

@hawicz
Copy link
Member

hawicz commented Nov 22, 2019

Note that if it was really a NaN value (e.g. 0.0/0.0), you'd see "width": NaN

@Ekmansoft
Copy link
Author

Ekmansoft commented Nov 22, 2019 via email

@Ekmansoft
Copy link
Author

We just got another ticket on this problem today.

This time it seems like the floating point value is serialized as the character Y, which causes the parser to complain.

... "Pid": { "kp": Y, "ki": 3.0, "kd": 18.0 } ...

@Ekmansoft
Copy link
Author

Ekmansoft commented Dec 2, 2019

We are using this function multiple times in our app (possibly in different threads)

json_c_set_serialization_double_format("%.3g", JSON_C_OPTION_GLOBAL);

with parameter "%.3g", "%.6g" and "%.4g"

And it might be that the failing double value is always the first after calling the above function...

@hawicz
Copy link
Member

hawicz commented Dec 3, 2019

Careful with threading, you shouldn't expect that using the same (portions of the) object tree across different threads is completely safe, especially if more than one thread is serializing at the same time.
If you're running threaded, I would recommend against setting the global format, and instead see if you can use JSON_C_OPTION_THREAD instead: we don't have any memory barriers in place so I suspect explicitly using thread-local storage would be a bit more reliable.

@Ekmansoft
Copy link
Author

Ok, thanks. We will try using the thread setting. Should work fine for us since we are not sharing json-objects between threads.

@hawicz
Copy link
Member

hawicz commented Dec 11, 2019

I'm assuming more careful threaded handling has solved your problem. If you still see an issue, and can provide an example, please reopen.

@hawicz hawicz closed this as completed Dec 11, 2019
@Ekmansoft
Copy link
Author

Ekmansoft commented Dec 11, 2019 via email

@Ekmansoft
Copy link
Author

Ekmansoft commented Aug 7, 2020

It has worked quite well since we made the thread change above, but today I received a report that one double value <51.0> had been encoded as just "51" in the string.

In effect one double in an array of eight doubles was encoded in the string as if it had been an integer. Could this happen?

@hawicz
Copy link
Member

hawicz commented Aug 7, 2020

If you're using a very old version of json-c, yes, but the most recent release (0.15) always adds a ".0", and I think anything starting from 0.13 should be fine. If you have a reproducible test case, please open a new bug and provide it.

@Ekmansoft
Copy link
Author

Ekmansoft commented Aug 7, 2020 via email

@dota17
Copy link
Member

dota17 commented Aug 8, 2020

I parsed the "[50.0, 1.00, 63.1, 0.0]" and get the same array in master branch and 0.13.1. How about providing a test case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants