Skip to content
This repository
Browse code

* 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>


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@8 327403b1-1117-474d-bef2-5cb71233fd97
  • Loading branch information...
commit 0370baa74c76e49abffdcd90f70494b2d5298f1a 1 parent 7b899b6
Michael Clark michaeljclark authored

Showing 4 changed files with 17 additions and 5 deletions. Show diff stats Hide diff stats

  1. +6 0 ChangeLog
  2. +1 1  README.html
  3. +7 4 json_tokener.c
  4. +3 0  test1.c
6 ChangeLog
... ... @@ -1,3 +1,9 @@
  1 +0.4
  2 + * Fix additional error case in object parsing
  3 + * Add back sign reversal in nested object parse as error pointer
  4 + value is negative, while error value is positive.
  5 + Michael Clark <michael@metaparadigm.com>
  6 +
1 7 0.3
2 8 * fix pointer arithmetic bug for error pointer check in is_error() macro
3 9 * fix type passed to printbuf_memappend in json_tokener
2  README.html
@@ -8,7 +8,7 @@
8 8 </head>
9 9 <body>
10 10 <h2>JSON-C - A JSON implementation in C</h2>
11   - <p>Latest release: <a href="json-c-0.3.tar.gz">json-c-0.3.tar.gz</a></p>
  11 + <p>Latest release: <a href="json-c-0.4.tar.gz">json-c-0.4.tar.gz</a></p>
12 12 <p>JSON-C implements a reference counting object model that allows you to easily
13 13 construct JSON objects in C, output them as JSON formatted strings and parse
14 14 JSON formatted strings back into the C representation of JSON objects.</p>
11 json_tokener.c
... ... @@ -1,5 +1,5 @@
1 1 /*
2   - * $Id: json_tokener.c,v 1.15 2005/07/15 03:19:43 mclark Exp $
  2 + * $Id: json_tokener.c,v 1.17 2005/07/26 07:49:11 mclark Exp $
3 3 *
4 4 * Copyright Metaparadigm Pte. Ltd. 2004.
5 5 * Michael Clark <michael@metaparadigm.com>
@@ -350,7 +350,7 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this)
350 350 } else {
351 351 obj = json_tokener_do_parse(this);
352 352 if(is_error(obj)) {
353   - err = (enum json_tokener_error)obj;
  353 + err = -(enum json_tokener_error)obj;
354 354 goto out;
355 355 }
356 356 json_object_array_add(current, obj);
@@ -389,6 +389,9 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this)
389 389 printbuf_reset(this->pb);
390 390 state = json_tokener_state_object_field;
391 391 start_offset = ++this->pos;
  392 + } else {
  393 + err = json_tokener_error_parse_object;
  394 + goto out;
392 395 }
393 396 break;
394 397
@@ -419,7 +422,7 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this)
419 422 case json_tokener_state_object_value:
420 423 obj = json_tokener_do_parse(this);
421 424 if(is_error(obj)) {
422   - err = (enum json_tokener_error)obj;
  425 + err = -(enum json_tokener_error)obj;
423 426 goto out;
424 427 }
425 428 json_object_object_add(current, obj_field_name, obj);
@@ -457,5 +460,5 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this)
457 460 mc_debug("json_tokener_do_parse: error=%d state=%d char=%c\n",
458 461 err, state, c);
459 462 json_object_put(current);
460   - return error_ptr((ptrdiff_t)-err);
  463 + return error_ptr(-err);
461 464 }
3  test1.c
@@ -121,6 +121,9 @@ int main(int argc, char **argv)
121 121 printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
122 122 json_object_put(new_obj);
123 123
  124 + new_obj = json_tokener_parse("{ foo }");
  125 + if(is_error(new_obj)) printf("got error as expected\n");
  126 +
124 127 new_obj = json_tokener_parse("foo");
125 128 if(is_error(new_obj)) printf("got error as expected\n");
126 129

0 comments on commit 0370baa

Please sign in to comment.
Something went wrong with that request. Please try again.