You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
The construct below causes indefinite hang where strlen(str)==0, Is this a deliberate design?
do
{
jobj=json_tokener_parse_ex(jtok, str, strlen(str));
}
while ((jerr=json_tokener_get_error(jtok))==json_tokener_continue);
The text was updated successfully, but these errors were encountered:
Yes, though indirectly. json_tokener_parse_ex() is meant to be usable to parse a json object across multiple calls, so having nothing to parse yet doesn't mean the next call won't provide some valid json syntax.
That loop looks pretty odd. Even if str wasn't empty, why would you want to keep parsing it? Say you pass in a str that just contains a left curly brace "{". That code will loop, internally creating a whole series of nested objects, until you reach the default depth limit of 32, or if you've adjusted max_depth, until you run out of memory.
hawicz
changed the title
json_tokener_parse_ex() hangs on zero-length string
json_tokener_parse_ex() returns json_tokener_continue on zero-length string
Nov 10, 2016
Just to be clear, json_tokener_parse_ex() does not hang. It returns json_tokener_continue, so the loop in the sample code above is essentially an infinite loop.
Thanks for clarifying. I will revisit my implementation in light of the above. For what it is worth, I tend to remember i got stuck on "hanging" as opposed to "spinning". Reason I say that because the way i stumbled across this is when my threads were hanging on to the mutex as they were stuck in the above call when json str was empty (introspected via gdb). I don't recall my cpus going through the roof at the time...
Hi,
The construct below causes indefinite hang where strlen(str)==0, Is this a deliberate design?
do
{
jobj=json_tokener_parse_ex(jtok, str, strlen(str));
}
while ((jerr=json_tokener_get_error(jtok))==json_tokener_continue);
The text was updated successfully, but these errors were encountered: