Revision 11e8a46c json-parser.c

b/json-parser.c
275 275
 */
276 276
static int parse_pair(JSONParserContext *ctxt, QDict *dict, QList **tokens, va_list *ap)
277 277
{
278
    QObject *key, *token = NULL, *value, *peek;
278
    QObject *key = NULL, *token = NULL, *value, *peek;
279 279
    QList *working = qlist_copy(*tokens);
280 280

  
281 281
    peek = qlist_peek(working);
282
    if (peek == NULL) {
283
        parse_error(ctxt, NULL, "premature EOI");
284
        goto out;
285
    }
286

  
282 287
    key = parse_value(ctxt, &working, ap);
283 288
    if (!key || qobject_type(key) != QTYPE_QSTRING) {
284 289
        parse_error(ctxt, peek, "key is not a string in object");
......
286 291
    }
287 292

  
288 293
    token = qlist_pop(working);
294
    if (token == NULL) {
295
        parse_error(ctxt, NULL, "premature EOI");
296
        goto out;
297
    }
298

  
289 299
    if (!token_is_operator(token, ':')) {
290 300
        parse_error(ctxt, token, "missing : in object pair");
291 301
        goto out;
......
321 331
    QList *working = qlist_copy(*tokens);
322 332

  
323 333
    token = qlist_pop(working);
334
    if (token == NULL) {
335
        goto out;
336
    }
337

  
324 338
    if (!token_is_operator(token, '{')) {
325 339
        goto out;
326 340
    }
......
330 344
    dict = qdict_new();
331 345

  
332 346
    peek = qlist_peek(working);
347
    if (peek == NULL) {
348
        parse_error(ctxt, NULL, "premature EOI");
349
        goto out;
350
    }
351

  
333 352
    if (!token_is_operator(peek, '}')) {
334 353
        if (parse_pair(ctxt, dict, &working, ap) == -1) {
335 354
            goto out;
336 355
        }
337 356

  
338 357
        token = qlist_pop(working);
358
        if (token == NULL) {
359
            parse_error(ctxt, NULL, "premature EOI");
360
            goto out;
361
        }
362

  
339 363
        while (!token_is_operator(token, '}')) {
340 364
            if (!token_is_operator(token, ',')) {
341 365
                parse_error(ctxt, token, "expected separator in dict");
......
349 373
            }
350 374

  
351 375
            token = qlist_pop(working);
376
            if (token == NULL) {
377
                parse_error(ctxt, NULL, "premature EOI");
378
                goto out;
379
            }
352 380
        }
353 381
        qobject_decref(token);
354 382
        token = NULL;
......
377 405
    QList *working = qlist_copy(*tokens);
378 406

  
379 407
    token = qlist_pop(working);
408
    if (token == NULL) {
409
        goto out;
410
    }
411

  
380 412
    if (!token_is_operator(token, '[')) {
381 413
        goto out;
382 414
    }
......
386 418
    list = qlist_new();
387 419

  
388 420
    peek = qlist_peek(working);
421
    if (peek == NULL) {
422
        parse_error(ctxt, NULL, "premature EOI");
423
        goto out;
424
    }
425

  
389 426
    if (!token_is_operator(peek, ']')) {
390 427
        QObject *obj;
391 428

  
......
398 435
        qlist_append_obj(list, obj);
399 436

  
400 437
        token = qlist_pop(working);
438
        if (token == NULL) {
439
            parse_error(ctxt, NULL, "premature EOI");
440
            goto out;
441
        }
442

  
401 443
        while (!token_is_operator(token, ']')) {
402 444
            if (!token_is_operator(token, ',')) {
403 445
                parse_error(ctxt, token, "expected separator in list");
......
416 458
            qlist_append_obj(list, obj);
417 459

  
418 460
            token = qlist_pop(working);
461
            if (token == NULL) {
462
                parse_error(ctxt, NULL, "premature EOI");
463
                goto out;
464
            }
419 465
        }
420 466

  
421 467
        qobject_decref(token);
......
444 490
    QList *working = qlist_copy(*tokens);
445 491

  
446 492
    token = qlist_pop(working);
493
    if (token == NULL) {
494
        goto out;
495
    }
447 496

  
448 497
    if (token_get_type(token) != JSON_KEYWORD) {
449 498
        goto out;
......
481 530
    }
482 531

  
483 532
    token = qlist_pop(working);
533
    if (token == NULL) {
534
        goto out;
535
    }
484 536

  
485 537
    if (token_is_escape(token, "%p")) {
486 538
        obj = va_arg(*ap, QObject *);
......
520 572
    QList *working = qlist_copy(*tokens);
521 573

  
522 574
    token = qlist_pop(working);
575
    if (token == NULL) {
576
        goto out;
577
    }
578

  
523 579
    switch (token_get_type(token)) {
524 580
    case JSON_STRING:
525 581
        obj = QOBJECT(qstring_from_escaped_str(ctxt, token));

Also available in: Unified diff