1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 19:34:05 +00:00

update snapshot of Jean Gressmann's JSON parser

This commit is contained in:
Charles Kerr 2008-07-21 16:11:00 +00:00
parent 1737324118
commit 4bff7981b7

View file

@ -32,7 +32,9 @@ SOFTWARE.
For the added features the license above applies also.
Changelog:
2008/07/19
- Removed some duplicate code & debugging variable (Charles.Kerr@noaa.gov)
2008/05/28
- Made JSON_value structure ansi C compliant. This bug was report by
trisk@acm.jhu.edu
@ -57,7 +59,7 @@ SOFTWARE.
#include "ConvertUTF.h"
#if _MSC_VER >= 1400 /* Visual Studio 2005 and up */
# pragma warning(disable:4996) /* unsecure sscanf */
# pragma warning(disable:4996) // unsecure sscanf
#endif
@ -293,12 +295,14 @@ push(JSON_parser jc, int mode)
jc->top += 1;
if (jc->depth < 0) {
if (jc->top >= jc->stack_capacity) {
size_t bytes_to_allocate;
jc->stack_capacity *= 2;
bytes_to_allocate = jc->stack_capacity * sizeof(jc->static_stack[0]);
if (jc->stack == &jc->static_stack[0]) {
jc->stack = (signed char*)malloc(jc->stack_capacity * sizeof(jc->static_stack[0]));
jc->stack = (signed char*)malloc(bytes_to_allocate);
memcpy(jc->stack, jc->static_stack, sizeof(jc->static_stack));
} else {
jc->stack = (signed char*)realloc(jc->stack, jc->stack_capacity * sizeof(jc->static_stack[0]));
jc->stack = (signed char*)realloc(jc->stack, bytes_to_allocate);
}
}
} else {
@ -426,12 +430,14 @@ new_JSON_parser(JSON_config* config)
static void grow_parse_buffer(JSON_parser jc)
{
size_t bytes_to_allocate;
jc->parse_buffer_capacity *= 2;
bytes_to_allocate = jc->parse_buffer_capacity * sizeof(jc->parse_buffer[0]);
if (jc->parse_buffer == &jc->static_parse_buffer[0]) {
jc->parse_buffer = (char*)malloc(jc->parse_buffer_capacity * sizeof(jc->parse_buffer[0]));
jc->parse_buffer = (char*)malloc(bytes_to_allocate);
memcpy(jc->parse_buffer, jc->static_parse_buffer, jc->parse_buffer_count);
} else {
jc->parse_buffer = (char*)realloc(jc->parse_buffer, jc->parse_buffer_capacity * sizeof(jc->parse_buffer[0]));
jc->parse_buffer = (char*)realloc(jc->parse_buffer, bytes_to_allocate);
}
}
@ -439,7 +445,7 @@ static void grow_parse_buffer(JSON_parser jc)
do {\
if (jc->parse_buffer_count + 1 >= jc->parse_buffer_capacity) grow_parse_buffer(jc);\
jc->parse_buffer[jc->parse_buffer_count++] = c;\
jc->parse_buffer[jc->parse_buffer_count] = 0;\
jc->parse_buffer[jc->parse_buffer_count] = 0;\
} while (0)
@ -456,7 +462,6 @@ static int parse_parse_buffer(JSON_parser jc)
jc->type == JSON_T_FLOAT ||
jc->type == JSON_T_INTEGER ||
jc->type == JSON_T_STRING);
switch(jc->type) {
case JSON_T_FLOAT: