On 11/25/2015 02:23 PM, Markus Armbruster wrote:
> We backtrack in parse_value(), even though JSON is LL(1) and thus can
> be parsed by straightforward recursive descent.  Do exactly that.
> 
> Based on an almost-correct patch from Paolo Bonzini.
> 
> Signed-off-by: Markus Armbruster <arm...@redhat.com>
> ---
>  qobject/json-parser.c | 165 
> ++++++++++++++------------------------------------
>  1 file changed, 47 insertions(+), 118 deletions(-)
> 

>  static QObject *parse_value(JSONParserContext *ctxt, va_list *ap)
>  {
> -    QObject *obj;
> +    QObject *token;
>  
> -    obj = parse_object(ctxt, ap);
> -    if (obj == NULL) {
> -        obj = parse_array(ctxt, ap);
> -    }
> -    if (obj == NULL) {
> -        obj = parse_escape(ctxt, ap);
> -    }
> -    if (obj == NULL) {
> -        obj = parse_keyword(ctxt);
> -    } 
> -    if (obj == NULL) {
> -        obj = parse_literal(ctxt);
> +    token = parser_context_peek_token(ctxt);
> +    if (token == NULL) {
> +        parse_error(ctxt, NULL, "premature EOI");

Should we spell that out as 'end of input'?

But that's cosmetic, and doesn't affect correctness of the conversion.

Reviewed-by: Eric Blake <ebl...@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to