diff options
author | ehaszla <ehaszla@327403b1-1117-474d-bef2-5cb71233fd97> | 2010-12-07 18:15:35 +0000 |
---|---|---|
committer | ehaszla <ehaszla@327403b1-1117-474d-bef2-5cb71233fd97> | 2010-12-07 18:15:35 +0000 |
commit | 252669cee672b101cc43b2baae86db4a8bcb80eb (patch) | |
tree | f9735cbbf9703534b59e8c78b1881eb21cf583f4 /json_util.c | |
parent | f1ae67dbf0d5d921d2786cc63878dcc21e2a32ea (diff) | |
download | json-c-252669cee672b101cc43b2baae86db4a8bcb80eb.tar.gz |
Simplify things by storing integer values only as int64_t's internally, and
omit the range check during parsing since we already have the checks when
accessing the value. There is no longer a json_type_int64, only json_type_int.
Fix some problems with parsing 0 and -0 values, and add a couple of tests.
Fix some minor compile issues on HPUX environments.
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@60 327403b1-1117-474d-bef2-5cb71233fd97
Diffstat (limited to 'json_util.c')
-rw-r--r-- | json_util.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/json_util.c b/json_util.c index 0dcd6d5..9eca953 100644 --- a/json_util.c +++ b/json_util.c @@ -10,6 +10,7 @@ */ #include "config.h" +#undef realloc #include <stdio.h> #include <stdlib.h> @@ -131,7 +132,7 @@ int json_parse_int64(const char *buf, int64_t *retval) int64_t num64; if (sscanf(buf, "%" SCNd64, &num64) != 1) { - printf("Failed to parse, sscanf != 1\n"); + MC_DEBUG("Failed to parse, sscanf != 1\n"); return 1; } const char *buf_skip_space = buf; @@ -144,9 +145,11 @@ int json_parse_int64(const char *buf, int64_t *retval) buf_skip_space++; orig_has_neg = 1; } - // Skip leading zeros - while (*buf_skip_space == '0' && *buf_skip_space) + // Skip leading zeros, but keep at least one digit + while (buf_skip_space[0] == '0' && buf_skip_space[1] != '\0') buf_skip_space++; + if (buf_skip_space[0] == '0' && buf_skip_space[1] == '\0') + orig_has_neg = 0; // "-0" is the same as just plain "0" if (errno != ERANGE) { @@ -171,7 +174,7 @@ int json_parse_int64(const char *buf, int64_t *retval) if (orig_has_neg != recheck_has_neg || strncmp(buf_skip_space, buf_cmp_start, strlen(buf_cmp_start)) != 0 || (strlen(buf_skip_space) != buf_cmp_len && - isdigit(buf_skip_space[buf_cmp_len]) + isdigit((int)buf_skip_space[buf_cmp_len]) ) ) { @@ -188,3 +191,14 @@ int json_parse_int64(const char *buf, int64_t *retval) *retval = num64; return 0; } + +#if HAVE_REALLOC == 0 +void* rpl_realloc(void* p, size_t n) +{ + if (n == 0) + n = 1; + if (p == 0) + return malloc(n); + return realloc(p, n); +} +#endif |