forkachild / C-Simple-JSON-Parser

Extremely lightweight, easy-to-use & blazing fast JSON parsing library written in pure C
https://forkachild.github.io/C-Simple-JSON-Parser/
MIT License
45 stars 16 forks source link

Fix string ptr increase after recursion #2

Closed jongilm closed 4 years ago

jongilm commented 4 years ago

Problem:

The code can enter an infinite loop after parsing a complex string that requires recursion.

Cause:

After recursively parsing of a child object, the string pointer is not incremented correctly. It is increased by the current _offset, rather than only the size of the child/recursed object(s).

e.g.

{"name":{"first":"John", "last":"Doe"}, "age":"21"}
0----+----1----+----2----+----3----+----4----+----
        0----+----1----+----2----+----

After parsing {"first":"John", "last":"Doe"}, the string pointer is incorrectly advanced to the "2", instead of the ",".

Solution:

Increment the string pointer by the size of the recursed child objects, rather than the current (already incremented) _offset.