Skip to content

Commit

Permalink
* Fix additional error case in object parsing
Browse files Browse the repository at this point in the history
  * Add back sign reversal in nested object parse as error pointer
    value is negative, while error value is positive.
    Michael Clark <michael@metaparadigm.com>


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@8 327403b1-1117-474d-bef2-5cb71233fd97
  • Loading branch information
michaeljclark committed Mar 13, 2007
1 parent 7b899b6 commit 0370baa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
0.4
* Fix additional error case in object parsing
* Add back sign reversal in nested object parse as error pointer
value is negative, while error value is positive.
Michael Clark <michael@metaparadigm.com>

0.3 0.3
* fix pointer arithmetic bug for error pointer check in is_error() macro * fix pointer arithmetic bug for error pointer check in is_error() macro
* fix type passed to printbuf_memappend in json_tokener * fix type passed to printbuf_memappend in json_tokener
Expand Down
2 changes: 1 addition & 1 deletion README.html
Expand Up @@ -8,7 +8,7 @@
</head> </head>
<body> <body>
<h2>JSON-C - A JSON implementation in C</h2> <h2>JSON-C - A JSON implementation in C</h2>
<p>Latest release: <a href="json-c-0.3.tar.gz">json-c-0.3.tar.gz</a></p> <p>Latest release: <a href="json-c-0.4.tar.gz">json-c-0.4.tar.gz</a></p>
<p>JSON-C implements a reference counting object model that allows you to easily <p>JSON-C implements a reference counting object model that allows you to easily
construct JSON objects in C, output them as JSON formatted strings and parse construct JSON objects in C, output them as JSON formatted strings and parse
JSON formatted strings back into the C representation of JSON objects.</p> JSON formatted strings back into the C representation of JSON objects.</p>
Expand Down
11 changes: 7 additions & 4 deletions json_tokener.c
@@ -1,5 +1,5 @@
/* /*
* $Id: json_tokener.c,v 1.15 2005/07/15 03:19:43 mclark Exp $ * $Id: json_tokener.c,v 1.17 2005/07/26 07:49:11 mclark Exp $
* *
* Copyright Metaparadigm Pte. Ltd. 2004. * Copyright Metaparadigm Pte. Ltd. 2004.
* Michael Clark <michael@metaparadigm.com> * Michael Clark <michael@metaparadigm.com>
Expand Down Expand Up @@ -350,7 +350,7 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this)
} else { } else {
obj = json_tokener_do_parse(this); obj = json_tokener_do_parse(this);
if(is_error(obj)) { if(is_error(obj)) {
err = (enum json_tokener_error)obj; err = -(enum json_tokener_error)obj;
goto out; goto out;
} }
json_object_array_add(current, obj); json_object_array_add(current, obj);
Expand Down Expand Up @@ -389,6 +389,9 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this)
printbuf_reset(this->pb); printbuf_reset(this->pb);
state = json_tokener_state_object_field; state = json_tokener_state_object_field;
start_offset = ++this->pos; start_offset = ++this->pos;
} else {
err = json_tokener_error_parse_object;
goto out;
} }
break; break;


Expand Down Expand Up @@ -419,7 +422,7 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this)
case json_tokener_state_object_value: case json_tokener_state_object_value:
obj = json_tokener_do_parse(this); obj = json_tokener_do_parse(this);
if(is_error(obj)) { if(is_error(obj)) {
err = (enum json_tokener_error)obj; err = -(enum json_tokener_error)obj;
goto out; goto out;
} }
json_object_object_add(current, obj_field_name, obj); json_object_object_add(current, obj_field_name, obj);
Expand Down Expand Up @@ -457,5 +460,5 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this)
mc_debug("json_tokener_do_parse: error=%d state=%d char=%c\n", mc_debug("json_tokener_do_parse: error=%d state=%d char=%c\n",
err, state, c); err, state, c);
json_object_put(current); json_object_put(current);
return error_ptr((ptrdiff_t)-err); return error_ptr(-err);
} }
3 changes: 3 additions & 0 deletions test1.c
Expand Up @@ -121,6 +121,9 @@ int main(int argc, char **argv)
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj)); printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
json_object_put(new_obj); json_object_put(new_obj);


new_obj = json_tokener_parse("{ foo }");
if(is_error(new_obj)) printf("got error as expected\n");

new_obj = json_tokener_parse("foo"); new_obj = json_tokener_parse("foo");
if(is_error(new_obj)) printf("got error as expected\n"); if(is_error(new_obj)) printf("got error as expected\n");


Expand Down

0 comments on commit 0370baa

Please sign in to comment.