mirror of
https://github.com/json-c/json-c.git
synced 2026-04-05 13:29:06 +08:00
Perform better error checking in json_tokener_parse_verbose and rewrite json_tokener_parse to use that instead of json_tokener_parse_ex.
Fix a typo in the string represenations of the json_tokener_error_depth error (s/to deep/too deep/)
This commit is contained in:
committed by
Keith Derrick
parent
37e7467476
commit
9885b30c0e
@@ -47,7 +47,7 @@ static const char* json_false_str = "false";
|
|||||||
const char* json_tokener_errors[] = {
|
const char* json_tokener_errors[] = {
|
||||||
"success",
|
"success",
|
||||||
"continue",
|
"continue",
|
||||||
"nesting to deep",
|
"nesting too deep",
|
||||||
"unexpected end of data",
|
"unexpected end of data",
|
||||||
"unexpected character",
|
"unexpected character",
|
||||||
"null expected",
|
"null expected",
|
||||||
@@ -122,17 +122,10 @@ void json_tokener_reset(struct json_tokener *tok)
|
|||||||
|
|
||||||
struct json_object* json_tokener_parse(const char *str)
|
struct json_object* json_tokener_parse(const char *str)
|
||||||
{
|
{
|
||||||
struct json_tokener* tok;
|
enum json_tokener_error jerr_ignored;
|
||||||
struct json_object* obj;
|
struct json_object* obj;
|
||||||
|
obj = json_tokener_parse_verbose(str, &jerr_ignored);
|
||||||
tok = json_tokener_new();
|
return obj;
|
||||||
if (!tok)
|
|
||||||
return NULL;
|
|
||||||
obj = json_tokener_parse_ex(tok, str, -1);
|
|
||||||
if(tok->err != json_tokener_success)
|
|
||||||
obj = NULL;
|
|
||||||
json_tokener_free(tok);
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error)
|
struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error)
|
||||||
@@ -141,9 +134,13 @@ struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokene
|
|||||||
struct json_object* obj;
|
struct json_object* obj;
|
||||||
|
|
||||||
tok = json_tokener_new();
|
tok = json_tokener_new();
|
||||||
|
if (!tok)
|
||||||
|
return NULL;
|
||||||
obj = json_tokener_parse_ex(tok, str, -1);
|
obj = json_tokener_parse_ex(tok, str, -1);
|
||||||
*error = tok->err;
|
*error = tok->err;
|
||||||
if(tok->err != json_tokener_success) {
|
if(tok->err != json_tokener_success) {
|
||||||
|
if (obj != NULL)
|
||||||
|
json_object_put(obj);
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user