Ignore:
Timestamp:
Apr 17, 2010, 1:29:02 PM (12 years ago)
Author:
charles
Message:

(trunk libT) update our JSON_parser snapshot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/JSON_parser.c

    r9973 r10492  
    1 /* JSON_parser.c */
    2 
    3 /* 2007-08-24 */
    4 
    51/*
    62Copyright (c) 2005 JSON.org
     
    2824
    2925/*
    30     Callbacks, comments, Unicode handling by Jean Gressmann (jean@0x42.de), 2007-2009.
    31    
    32     For the added features the license above applies also.
     26    Callbacks, comments, Unicode handling by Jean Gressmann (jean@0x42.de), 2007-2010.
    3327   
    3428    Changelog:
     29        2010-03-25
     30            Fixed buffer overrun in grow_parse_buffer & cleaned up code.
     31           
     32        2009-10-19
     33            Replaced long double in JSON_value_struct with double after reports
     34            of strtold being broken on some platforms (charles@transmissionbt.com).
     35           
    3536        2009-05-17
    3637            Incorporated benrudiak@googlemail.com fix for UTF16 decoding.
     
    6869#include <locale.h>
    6970
     71#include <evutil.h> /* evutil_strtoll() */
     72
    7073#include "JSON_parser.h"
    7174
     
    7376#   if _MSC_VER >= 1400 /* Visual Studio 2005 and up */
    7477#      pragma warning(disable:4996) /* unsecure sscanf */
     78#      pragma warning(disable:4127) /* conditional expression is constant */
    7579#   endif
    7680#endif
     
    155159};
    156160
    157 static const int ascii_class[128] = {
     161static const signed char ascii_class[128] = {
    158162/*
    159163    This array maps the 128 ASCII characters into character classes.
     
    244248
    245249
    246 static const int state_transition_table[NR_STATES][NR_CLASSES] = {
     250static const signed char state_transition_table[NR_STATES][NR_CLASSES] = {
    247251/*
    248252    The state transition table takes the current state and the current symbol,
     
    327331    }
    328332   
    329     jc->stack[jc->top] = mode;
     333    jc->stack[jc->top] = (signed char)mode;
    330334    return true;
    331335}
     
    439443    jc->callback = config->callback;
    440444    jc->ctx = config->callback_ctx;
    441     jc->allow_comments = config->allow_comments != 0;
    442     jc->handle_floats_manually = config->handle_floats_manually != 0;
     445    jc->allow_comments = (signed char)config->allow_comments != 0;
     446    jc->handle_floats_manually = (signed char)config->handle_floats_manually != 0;
    443447   
    444448    /* set up decimal point */
     
    450454static void grow_parse_buffer(JSON_parser jc)
    451455{
    452     size_t bytes_to_allocate;
     456    assert(jc->parse_buffer_capacity > 0);
     457
    453458    jc->parse_buffer_capacity *= 2;
    454     bytes_to_allocate = jc->parse_buffer_capacity * sizeof(jc->parse_buffer[0]);
    455459    if (jc->parse_buffer == &jc->static_parse_buffer[0]) {
    456         jc->parse_buffer = (char*)malloc(bytes_to_allocate);
     460        jc->parse_buffer = (char*)malloc(jc->parse_buffer_capacity);
    457461        memcpy(jc->parse_buffer, jc->static_parse_buffer, jc->parse_buffer_count);
    458462    } else {
    459         jc->parse_buffer = (char*)realloc(jc->parse_buffer, bytes_to_allocate);
     463        jc->parse_buffer = (char*)realloc(jc->parse_buffer, jc->parse_buffer_capacity);
    460464    }
    461465}
     
    463467#define parse_buffer_push_back_char(jc, c)\
    464468    do {\
    465         if (jc->parse_buffer_count + 1 >= jc->parse_buffer_capacity) grow_parse_buffer(jc);\
     469        if (jc->parse_buffer_count + 2 >= jc->parse_buffer_capacity) grow_parse_buffer(jc);\
    466470        jc->parse_buffer[jc->parse_buffer_count++] = c;\
    467471        jc->parse_buffer[jc->parse_buffer_count]   = 0;\
     
    493497                        value.vu.str.length = jc->parse_buffer_count;
    494498                    } else {
    495                         /*sscanf(jc->parse_buffer, "%Lf", &value.vu.float_value);*/
    496                        
    497499                        /* not checking with end pointer b/c there may be trailing ws */
    498500                        value.vu.float_value = strtod(jc->parse_buffer, NULL);
     
    574576        } else if (IS_HIGH_SURROGATE(uc)) {
    575577            /* save the high surrogate and wait for the low surrogate */
    576             jc->utf16_high_surrogate = uc;
     578            jc->utf16_high_surrogate = (UTF16)uc;
    577579            return true;
    578580        } else if (IS_LOW_SURROGATE(uc)) {
     
    692694    Change the state.
    693695*/
    694         jc->state = next_state;
     696        jc->state = (signed char)next_state;
    695697    } else {
    696698/*
     
    10021004
    10031005
    1004 
    10051006void init_JSON_config(JSON_config* config)
    10061007{
Note: See TracChangeset for help on using the changeset viewer.