Browse Source

Merge a406ec983d into 4b0c6de760

pull/740/merge
Even Rouault GitHub 3 years ago
parent
commit
a54407b393
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 28 deletions
  1. +2
    -2
      apps/json_parse.c
  2. +8
    -8
      json_object.c
  3. +5
    -5
      json_pointer.c
  4. +10
    -10
      json_tokener.c
  5. +2
    -2
      json_util.c
  6. +1
    -1
      tests/test_parse.c

+ 2
- 2
apps/json_parse.c View File

@@ -84,7 +84,7 @@ static int parseit(int fd, int (*callback)(struct json_object *))
// everything you can do with a tokener into json_util.c seems
// like the wrong approach.
size_t total_read = 0;
while ((ret = read(fd, buf, sizeof(buf))) > 0)
while ((ret = (int)read(fd, buf, sizeof(buf))) > 0)
{
total_read += ret;
int start_pos = 0;
@@ -98,7 +98,7 @@ static int parseit(int fd, int (*callback)(struct json_object *))
const char *aterr = (start_pos + parse_end < (int)sizeof(buf)) ?
&buf[start_pos + parse_end] : "";
fflush(stdout);
int fail_offset = total_read - ret + start_pos + parse_end;
int fail_offset = (int)(total_read - ret + start_pos + parse_end);
fprintf(stderr, "Failed at offset %d: %s %c\n", fail_offset,
json_tokener_error_desc(jerr), aterr[0]);
json_tokener_free(tok);


+ 8
- 8
json_object.c View File

@@ -201,7 +201,7 @@ static int json_escape_str(struct printbuf *pb, const char *str, size_t len, int
}

if (pos > start_offset)
printbuf_memappend(pb, str + start_offset, pos - start_offset);
printbuf_memappend(pb, str + start_offset, (int)(pos - start_offset));

if (c == '\b')
printbuf_memappend(pb, "\\b", 2);
@@ -228,7 +228,7 @@ static int json_escape_str(struct printbuf *pb, const char *str, size_t len, int
char sbuf[7];
if (pos > start_offset)
printbuf_memappend(pb, str + start_offset,
pos - start_offset);
(int)(pos - start_offset));
snprintf(sbuf, sizeof(sbuf), "\\u00%c%c", json_hex_chars[c >> 4],
json_hex_chars[c & 0xf]);
printbuf_memappend_fast(pb, sbuf, (int)sizeof(sbuf) - 1);
@@ -239,7 +239,7 @@ static int json_escape_str(struct printbuf *pb, const char *str, size_t len, int
}
}
if (pos > start_offset)
printbuf_memappend(pb, str + start_offset, pos - start_offset);
printbuf_memappend(pb, str + start_offset, (int)(pos - start_offset));
return 0;
}

@@ -679,7 +679,7 @@ static int json_object_int_to_json_string(struct json_object *jso, struct printb
snprintf(sbuf, sizeof(sbuf), "%" PRId64, JC_INT(jso)->cint.c_int64);
else
snprintf(sbuf, sizeof(sbuf), "%" PRIu64, JC_INT(jso)->cint.c_uint64);
return printbuf_memappend(pb, sbuf, strlen(sbuf));
return printbuf_memappend(pb, sbuf, (int)strlen(sbuf));
}

struct json_object *json_object_new_int(int32_t i)
@@ -1062,7 +1062,7 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
/* drop trailing zeroes */
if (*p != 0)
*(++p) = 0;
size = p - buf;
size = (int)(p - buf);
}
}
// although unlikely, snprintf can fail
@@ -1133,7 +1133,7 @@ static int _json_object_userdata_to_json_string(struct json_object *jso, struct
int json_object_userdata_to_json_string(struct json_object *jso, struct printbuf *pb, int level,
int flags)
{
int userdata_len = strlen((const char *)jso->_userdata);
int userdata_len = (int)strlen((const char *)jso->_userdata);
printbuf_memappend(pb, (const char *)jso->_userdata, userdata_len);
return userdata_len;
}
@@ -1301,7 +1301,7 @@ int json_object_get_string_len(const struct json_object *jso)
return 0;
switch (jso->o_type)
{
case json_type_string: return _json_object_get_string_len(JC_STRING_C(jso));
case json_type_string: return (int)_json_object_get_string_len(JC_STRING_C(jso));
default: return 0;
}
}
@@ -1673,7 +1673,7 @@ int json_c_shallow_copy_default(json_object *src, json_object *parent, const cha

case json_type_string:
*dst = json_object_new_string_len(get_string_component(src),
_json_object_get_string_len(JC_STRING(src)));
(int)_json_object_get_string_len(JC_STRING(src)));
break;

case json_type_object: *dst = json_object_new_object(); break;


+ 5
- 5
json_pointer.c View File

@@ -29,8 +29,8 @@

static void string_replace_all_occurrences_with_char(char *s, const char *occur, char repl_char)
{
int slen = strlen(s);
int skip = strlen(occur) - 1; /* length of the occurrence, minus the char we're replacing */
size_t slen = strlen(s);
int skip = (int)strlen(occur) - 1; /* length of the occurrence, minus the char we're replacing */
char *p = s;
while ((p = strstr(p, occur)))
{
@@ -43,7 +43,7 @@ static void string_replace_all_occurrences_with_char(char *s, const char *occur,

static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx)
{
int i, len = strlen(path);
int i, len = (int)strlen(path);
/* this code-path optimizes a bit, for when we reference the 0-9 index range
* in a JSON array and because leading zeros not allowed
*/
@@ -73,14 +73,14 @@ static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx
}
}

*idx = strtol(path, NULL, 10);
*idx = (int)strtol(path, NULL, 10);
if (*idx < 0)
{
errno = EINVAL;
return 0;
}
check_oob:
len = json_object_array_length(jo);
len = (int)json_object_array_length(jo);
if (*idx >= len)
{
errno = ENOENT;


+ 10
- 10
json_tokener.c View File

@@ -560,11 +560,11 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok))
{
printbuf_memappend_fast(tok->pb, case_start,
str - case_start);
(int)(str - case_start));
goto out;
}
}
printbuf_memappend_fast(tok->pb, case_start, 1 + str - case_start);
printbuf_memappend_fast(tok->pb, case_start, 1 + (int)(str - case_start));
state = json_tokener_state_comment_end;
}
break;
@@ -578,11 +578,11 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok))
{
printbuf_memappend_fast(tok->pb, case_start,
str - case_start);
(int)(str - case_start));
goto out;
}
}
printbuf_memappend_fast(tok->pb, case_start, str - case_start);
printbuf_memappend_fast(tok->pb, case_start, (int)(str - case_start));
MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf);
state = json_tokener_state_eatws;
}
@@ -610,7 +610,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
if (c == tok->quote_char)
{
printbuf_memappend_fast(tok->pb, case_start,
str - case_start);
(int)(str - case_start));
current =
json_object_new_string_len(tok->pb->buf, tok->pb->bpos);
if (current == NULL)
@@ -622,7 +622,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
else if (c == '\\')
{
printbuf_memappend_fast(tok->pb, case_start,
str - case_start);
(int)(str - case_start));
saved_state = json_tokener_state_string;
state = json_tokener_state_string_escape;
break;
@@ -630,7 +630,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok))
{
printbuf_memappend_fast(tok->pb, case_start,
str - case_start);
(int)(str - case_start));
goto out;
}
}
@@ -1130,7 +1130,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
if (c == tok->quote_char)
{
printbuf_memappend_fast(tok->pb, case_start,
str - case_start);
(int)(str - case_start));
obj_field_name = strdup(tok->pb->buf);
saved_state = json_tokener_state_object_field_end;
state = json_tokener_state_eatws;
@@ -1139,7 +1139,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
else if (c == '\\')
{
printbuf_memappend_fast(tok->pb, case_start,
str - case_start);
(int)(str - case_start));
saved_state = json_tokener_state_object_field;
state = json_tokener_state_string_escape;
break;
@@ -1147,7 +1147,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok))
{
printbuf_memappend_fast(tok->pb, case_start,
str - case_start);
(int)(str - case_start));
goto out;
}
}


+ 2
- 2
json_util.c View File

@@ -107,7 +107,7 @@ struct json_object *json_object_from_fd_ex(int fd, int in_depth)
return NULL;
}

while ((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0)
while ((ret = (int)read(fd, buf, JSON_FILE_BUF_SIZE)) > 0)
{
if (printbuf_memappend(pb, buf, ret) < 0)
{
@@ -207,7 +207,7 @@ static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const
wpos = 0;
while (wpos < wsize)
{
if ((ret = write(fd, json_str + wpos, wsize - wpos)) < 0)
if ((ret = (int)write(fd, json_str + wpos, wsize - wpos)) < 0)
{
_json_c_set_last_err("json_object_to_fd: error writing file %s: %s\n",
filename, strerror(errno));


+ 1
- 1
tests/test_parse.c View File

@@ -53,7 +53,7 @@ static void single_incremental_parse(const char *test_string, int clear_serializ
all_at_once_str = json_object_to_json_string(all_at_once_obj);

tok = json_tokener_new();
int test_string_len = strlen(test_string) + 1; // Including '\0' !
int test_string_len = (int)strlen(test_string) + 1; // Including '\0' !
for (ii = 0; ii < test_string_len; ii += chunksize)
{
int len_to_parse = chunksize;


Loading…
Cancel
Save