mirror of
https://github.com/rafagafe/tiny-json.git
synced 2024-11-17 11:35:30 +00:00
commit
1c62646c71
19
tiny-json.c
19
tiny-json.c
@ -33,8 +33,8 @@
|
|||||||
|
|
||||||
/** Structure to handle a heap of JSON properties. */
|
/** Structure to handle a heap of JSON properties. */
|
||||||
typedef struct jsonStaticPool_s {
|
typedef struct jsonStaticPool_s {
|
||||||
json_t* const mem; /**< Pointer to array of json properties. */
|
json_t* mem; /**< Pointer to array of json properties. */
|
||||||
unsigned int const qty; /**< Length of the array of json properties. */
|
unsigned int qty; /**< Length of the array of json properties. */
|
||||||
unsigned int nextFree; /**< The index of the next free json property. */
|
unsigned int nextFree; /**< The index of the next free json property. */
|
||||||
jsonPool_t pool;
|
jsonPool_t pool;
|
||||||
} jsonStaticPool_t;
|
} jsonStaticPool_t;
|
||||||
@ -81,14 +81,11 @@ json_t const* json_createWithPool( char *str, jsonPool_t *pool ) {
|
|||||||
|
|
||||||
/* Parse a string to get a json. */
|
/* Parse a string to get a json. */
|
||||||
json_t const* json_create( char* str, json_t mem[], unsigned int qty ) {
|
json_t const* json_create( char* str, json_t mem[], unsigned int qty ) {
|
||||||
jsonStaticPool_t spool = {
|
jsonStaticPool_t spool;
|
||||||
.mem = mem,
|
spool.mem = mem;
|
||||||
.qty = qty,
|
spool.qty = qty;
|
||||||
.pool = {
|
spool.pool.init = poolInit;
|
||||||
.init = poolInit,
|
spool.pool.alloc = poolAlloc;
|
||||||
.alloc = poolAlloc
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return json_createWithPool( str, &spool.pool );
|
return json_createWithPool( str, &spool.pool );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +290,7 @@ static char* numValue( char* ptr, json_t* property ) {
|
|||||||
static char const min[] = "-9223372036854775808";
|
static char const min[] = "-9223372036854775808";
|
||||||
static char const max[] = "9223372036854775807";
|
static char const max[] = "9223372036854775807";
|
||||||
unsigned int const maxdigits = ( negative? sizeof min: sizeof max ) - 1;
|
unsigned int const maxdigits = ( negative? sizeof min: sizeof max ) - 1;
|
||||||
unsigned int const len = ptr - value;
|
unsigned int const len = ( unsigned int const ) ( ptr - value );
|
||||||
if ( len > maxdigits ) return 0;
|
if ( len > maxdigits ) return 0;
|
||||||
if ( len == maxdigits ) {
|
if ( len == maxdigits ) {
|
||||||
char const tmp = *ptr;
|
char const tmp = *ptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user