Browse Source

Merge branch 'master' of https://github.com/json-c/json-c

tags/json-c-0.10-20120530
Eric Haszlakiewicz 13 years ago
parent
commit
15db9372f3
5 changed files with 18 additions and 7 deletions
  1. +3
    -1
      .gitignore
  2. +3
    -0
      json_inttypes.h
  3. +5
    -2
      json_object.c
  4. +6
    -3
      json_util.c
  5. +1
    -1
      printbuf.c

+ 3
- 1
.gitignore View File

@@ -21,4 +21,6 @@ test1
test2 test2
test4 test4
testSubDir testSubDir
test_parse_int64
test_parse_int64
Debug
Release

+ 3
- 0
json_inttypes.h View File

@@ -5,6 +5,9 @@
#if defined(_MSC_VER) && _MSC_VER < 1600 #if defined(_MSC_VER) && _MSC_VER < 1600


/* Anything less than Visual Studio C++ 10 is missing stdint.h and inttypes.h */ /* Anything less than Visual Studio C++ 10 is missing stdint.h and inttypes.h */
typedef __int32 int32_t;
#define INT32_MIN ((int32_t)_I32_MIN)
#define INT32_MAX ((int32_t)_I32_MAX)
typedef __int64 int64_t; typedef __int64 int64_t;
#define PRId64 "I64d" #define PRId64 "I64d"
#define SCNd64 "I64d" #define SCNd64 "I64d"


+ 5
- 2
json_object.c View File

@@ -321,10 +321,13 @@ struct json_object* json_object_new_int(int32_t i)


int32_t json_object_get_int(struct json_object *jso) int32_t json_object_get_int(struct json_object *jso)
{ {
int64_t cint64;
enum json_type o_type;

if(!jso) return 0; if(!jso) return 0;


enum json_type o_type = jso->o_type;
int64_t cint64 = jso->o.c_int64;
o_type = jso->o_type;
cint64 = jso->o.c_int64;


if (o_type == json_type_string) if (o_type == json_type_string)
{ {


+ 6
- 3
json_util.c View File

@@ -130,13 +130,15 @@ int json_object_to_file(char *filename, struct json_object *obj)
int json_parse_int64(const char *buf, int64_t *retval) int json_parse_int64(const char *buf, int64_t *retval)
{ {
int64_t num64; int64_t num64;
const char *buf_skip_space;
int orig_has_neg;
if (sscanf(buf, "%" SCNd64, &num64) != 1) if (sscanf(buf, "%" SCNd64, &num64) != 1)
{ {
MC_DEBUG("Failed to parse, sscanf != 1\n"); MC_DEBUG("Failed to parse, sscanf != 1\n");
return 1; return 1;
} }
const char *buf_skip_space = buf;
int orig_has_neg = 0;
buf_skip_space = buf;
orig_has_neg = 0;
// Skip leading spaces // Skip leading spaces
while (isspace((int)*buf_skip_space) && *buf_skip_space) while (isspace((int)*buf_skip_space) && *buf_skip_space)
buf_skip_space++; buf_skip_space++;
@@ -156,6 +158,7 @@ int json_parse_int64(const char *buf, int64_t *retval)
char buf_cmp[100]; char buf_cmp[100];
char *buf_cmp_start = buf_cmp; char *buf_cmp_start = buf_cmp;
int recheck_has_neg = 0; int recheck_has_neg = 0;
int buf_cmp_len;
snprintf(buf_cmp_start, sizeof(buf_cmp), "%" PRId64, num64); snprintf(buf_cmp_start, sizeof(buf_cmp), "%" PRId64, num64);
if (*buf_cmp_start == '-') if (*buf_cmp_start == '-')
{ {
@@ -164,7 +167,7 @@ int json_parse_int64(const char *buf, int64_t *retval)
} }
// No need to skip leading spaces or zeros here. // No need to skip leading spaces or zeros here.


int buf_cmp_len = strlen(buf_cmp_start);
buf_cmp_len = strlen(buf_cmp_start);
/** /**
* If the sign is different, or * If the sign is different, or
* some of the digits are different, or * some of the digits are different, or


+ 1
- 1
printbuf.c View File

@@ -65,7 +65,7 @@ int printbuf_memappend(struct printbuf *p, const char *buf, int size)
return size; return size;
} }


#if !HAVE_VSNPRINTF && defined(WIN32)
#if !HAVE_VSNPRINTF && defined(_MSC_VER)
# define vsnprintf _vsnprintf # define vsnprintf _vsnprintf
#elif !HAVE_VSNPRINTF /* !HAVE_VSNPRINTF */ #elif !HAVE_VSNPRINTF /* !HAVE_VSNPRINTF */
# error Need vsnprintf! # error Need vsnprintf!


Loading…
Cancel
Save