@@ -52,9 +52,9 @@ struct __json_element
5252typedef struct __json_member json_member_t ;
5353typedef struct __json_element json_element_t ;
5454
55- static int __json_string_length (const char * cursor )
55+ static int __json_string_length (const char * cursor , size_t * len )
5656{
57- int len = 0 ;
57+ size_t n = 0 ;
5858
5959 while (* cursor != '\"' )
6060 {
@@ -68,10 +68,11 @@ static int __json_string_length(const char *cursor)
6868 return -2 ;
6969
7070 cursor ++ ;
71- len ++ ;
71+ n ++ ;
7272 }
7373
74- return len ;
74+ * len = n ;
75+ return 0 ;
7576}
7677
7778static int __parse_json_hex4 (const char * cursor , const char * * end ,
@@ -504,6 +505,7 @@ static int __parse_json_members(const char *cursor, const char **end,
504505{
505506 json_member_t * memb ;
506507 int cnt = 0 ;
508+ size_t len ;
507509 int ret ;
508510
509511 while (isspace (* cursor ))
@@ -521,11 +523,11 @@ static int __parse_json_members(const char *cursor, const char **end,
521523 return -2 ;
522524
523525 cursor ++ ;
524- ret = __json_string_length (cursor );
526+ ret = __json_string_length (cursor , & len );
525527 if (ret < 0 )
526528 return ret ;
527529
528- memb = (json_member_t * )malloc (offsetof(json_member_t , name ) + ret + 1 );
530+ memb = (json_member_t * )malloc (offsetof(json_member_t , name ) + len + 1 );
529531 if (!memb )
530532 return -1 ;
531533
@@ -679,17 +681,18 @@ static int __parse_json_array(const char *cursor, const char **end,
679681static int __parse_json_value (const char * cursor , const char * * end ,
680682 int depth , json_value_t * val )
681683{
684+ size_t len ;
682685 int ret ;
683686
684687 switch (* cursor )
685688 {
686689 case '\"' :
687690 cursor ++ ;
688- ret = __json_string_length (cursor );
691+ ret = __json_string_length (cursor , & len );
689692 if (ret < 0 )
690693 return ret ;
691694
692- val -> value .string = (char * )malloc (ret + 1 );
695+ val -> value .string = (char * )malloc (len + 1 );
693696 if (!val -> value .string )
694697 return -1 ;
695698
@@ -847,7 +850,7 @@ static int __set_json_value(int type, va_list ap, json_value_t *val)
847850{
848851 json_value_t * src ;
849852 const char * str ;
850- int len ;
853+ size_t len ;
851854
852855 switch (type )
853856 {
@@ -916,7 +919,7 @@ static int __copy_json_members(const json_object_t *src, json_object_t *dest)
916919 struct list_head * pos ;
917920 json_member_t * entry ;
918921 json_member_t * memb ;
919- int len ;
922+ size_t len ;
920923
921924 list_for_each (pos , & src -> head )
922925 {
@@ -966,7 +969,7 @@ static int __copy_json_elements(const json_array_t *src, json_array_t *dest)
966969
967970static int __copy_json_value (const json_value_t * src , json_value_t * dest )
968971{
969- int len ;
972+ size_t len ;
970973
971974 switch (src -> type )
972975 {
@@ -1174,7 +1177,7 @@ static const json_value_t *__json_object_insert(const char *name,
11741177 json_object_t * obj )
11751178{
11761179 json_member_t * memb ;
1177- int len ;
1180+ size_t len ;
11781181
11791182 len = strlen (name );
11801183 memb = (json_member_t * )malloc (offsetof(json_member_t , name ) + len + 1 );
0 commit comments