Changeset 6375


Ignore:
Timestamp:
Jul 21, 2008, 4:11:00 PM (13 years ago)
Author:
charles
Message:

update snapshot of Jean Gressmann's JSON parser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/JSON_parser.c

    r6354 r6375  
    3333   
    3434    Changelog:
    35    
     35        2008/07/19
     36            - Removed some duplicate code & debugging variable (Charles.Kerr@noaa.gov)
     37       
    3638        2008/05/28
    3739            - Made JSON_value structure ansi C compliant. This bug was report by
     
    5860
    5961#if _MSC_VER >= 1400 /* Visual Studio 2005 and up */
    60 #       pragma warning(disable:4996) /* unsecure sscanf */
     62#       pragma warning(disable:4996) // unsecure sscanf
    6163#endif
    6264
     
    294296    if (jc->depth < 0) {
    295297        if (jc->top >= jc->stack_capacity) {
     298            size_t bytes_to_allocate;
    296299            jc->stack_capacity *= 2;
     300            bytes_to_allocate = jc->stack_capacity * sizeof(jc->static_stack[0]);
    297301            if (jc->stack == &jc->static_stack[0]) {
    298                 jc->stack = (signed char*)malloc(jc->stack_capacity * sizeof(jc->static_stack[0]));
     302                jc->stack = (signed char*)malloc(bytes_to_allocate);
    299303                memcpy(jc->stack, jc->static_stack, sizeof(jc->static_stack));
    300304            } else {
    301                 jc->stack = (signed char*)realloc(jc->stack, jc->stack_capacity * sizeof(jc->static_stack[0]));
     305                jc->stack = (signed char*)realloc(jc->stack, bytes_to_allocate);
    302306            }
    303307        }
     
    427431static void grow_parse_buffer(JSON_parser jc)
    428432{
     433    size_t bytes_to_allocate;
    429434    jc->parse_buffer_capacity *= 2;
     435    bytes_to_allocate = jc->parse_buffer_capacity * sizeof(jc->parse_buffer[0]);
    430436    if (jc->parse_buffer == &jc->static_parse_buffer[0]) {
    431         jc->parse_buffer = (char*)malloc(jc->parse_buffer_capacity * sizeof(jc->parse_buffer[0]));
     437        jc->parse_buffer = (char*)malloc(bytes_to_allocate);
    432438        memcpy(jc->parse_buffer, jc->static_parse_buffer, jc->parse_buffer_count);
    433439    } else {
    434         jc->parse_buffer = (char*)realloc(jc->parse_buffer, jc->parse_buffer_capacity * sizeof(jc->parse_buffer[0]));
     440        jc->parse_buffer = (char*)realloc(jc->parse_buffer, bytes_to_allocate);
    435441    }
    436442}
     
    440446        if (jc->parse_buffer_count + 1 >= jc->parse_buffer_capacity) grow_parse_buffer(jc);\
    441447        jc->parse_buffer[jc->parse_buffer_count++] = c;\
    442         jc->parse_buffer[jc->parse_buffer_count] = 0;\
     448        jc->parse_buffer[jc->parse_buffer_count]   = 0;\
    443449    } while (0)
    444450
     
    457463                jc->type == JSON_T_INTEGER ||
    458464                jc->type == JSON_T_STRING);
    459                
    460465       
    461466            switch(jc->type) {
Note: See TracChangeset for help on using the changeset viewer.