-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Crashing on json::at #2062
Comments
As far as I can tell, the code you work ought to work, as a It seems like the first part of your code directly catches a If so, you might have an issue where you have multiple definitions of |
Hello. Thank you for the reply. I can try catching out_of_range exception directly sure. And yes to answer your question, the json::parse_error does seem to work. Although it's strange because json::parse doesn't throw an exception even in the case of an invalid json.. It's the json::at throwing the exception. I'm confused about what you mean right here though.
Is it not good to try catch std::exception in several different locations? Edit: Trying to catch json out of range or std out of range still results in a crash. So I'm confused. Edit2: I'm pretty sure this is an error with my code because when I isolate the issue in a separate project..I don't crash. I just have no idea why calling it in the current project results in a crash. |
In order to asses your issue, we need the following information:
|
I apologise, the crashing was my fault. It's not a bug in your code. This thread can be closed. |
Thanks for checking back! |
Hi IreliaNina, |
Hello, I'm trying to parse json objects sent from the client to my server. I completely undertsand that the client at times might not send valid json data in case of packet manipulation but I assume if I try catch json parse and json.at then I shouldn't have any issues. But it seems when I try to catch json::at get an out of range exception.
The client is sending non valid empty json like this
{}
This is the code for checking the valid json
When I send an invalid json the code should return but instead it just crashes.
This is where it seems to be crashing.
#1 0x000000010003bfb5 in std::__1::__throw_out_of_range(char const*) at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdexcept:262
this std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>, std::__1::less<void>, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer> > > > * 0x000000010082ea10 size=0 0x000000010082ea10
I'm not sure if this is a bug with the source code or I'm doing something wrong but the way I see it, in case of an invalid json the code shouldn't continue. And if it does continue then catching std::exception should prevent the crash.
The text was updated successfully, but these errors were encountered: