Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
b88da9b0
T
Third Party CJSON
项目概览
OpenHarmony
/
Third Party CJSON
大约 1 年 前同步成功
通知
6
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party CJSON
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b88da9b0
编写于
11月 13, 2016
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initialize all variables
上级
a5ff796c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
55 deletion
+55
-55
cJSON.c
cJSON.c
+32
-32
cJSON_Utils.c
cJSON_Utils.c
+7
-7
test.c
test.c
+12
-12
test_utils.c
test_utils.c
+4
-4
未找到文件。
cJSON.c
浏览文件 @
b88da9b0
...
...
@@ -46,7 +46,7 @@
#error "Failed to determine the size of an integer"
#endif
static
const
char
*
global_ep
;
static
const
char
*
global_ep
=
NULL
;
const
char
*
cJSON_GetErrorPtr
(
void
)
{
...
...
@@ -80,8 +80,8 @@ static void (*cJSON_free)(void *ptr) = free;
static
char
*
cJSON_strdup
(
const
char
*
str
)
{
size_t
len
;
char
*
copy
;
size_t
len
=
0
;
char
*
copy
=
NULL
;
len
=
strlen
(
str
)
+
1
;
if
(
!
(
copy
=
(
char
*
)
cJSON_malloc
(
len
)))
...
...
@@ -122,7 +122,7 @@ static cJSON *cJSON_New_Item(void)
/* Delete a cJSON structure. */
void
cJSON_Delete
(
cJSON
*
c
)
{
cJSON
*
next
;
cJSON
*
next
=
NULL
;
while
(
c
)
{
next
=
c
->
next
;
...
...
@@ -244,8 +244,8 @@ typedef struct
/* realloc printbuffer if necessary to have at least "needed" bytes more */
static
char
*
ensure
(
printbuffer
*
p
,
int
needed
)
{
char
*
newbuffer
;
int
newsize
;
char
*
newbuffer
=
NULL
;
int
newsize
=
0
;
if
(
!
p
||
!
p
->
buffer
)
{
return
NULL
;
...
...
@@ -280,7 +280,7 @@ static char* ensure(printbuffer *p, int needed)
/* calculate the new length of the string in a printbuffer */
static
int
update
(
const
printbuffer
*
p
)
{
char
*
str
;
char
*
str
=
NULL
;
if
(
!
p
||
!
p
->
buffer
)
{
return
0
;
...
...
@@ -468,11 +468,11 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
{
const
char
*
ptr
=
str
+
1
;
const
char
*
end_ptr
=
str
+
1
;
char
*
ptr2
;
char
*
out
;
char
*
ptr2
=
NULL
;
char
*
out
=
NULL
;
int
len
=
0
;
unsigned
uc
;
unsigned
uc2
;
unsigned
uc
=
0
;
unsigned
uc2
=
0
;
/* not a string! */
if
(
*
str
!=
'\"'
)
...
...
@@ -643,12 +643,12 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
/* Render the cstring provided to an escaped version that can be printed. */
static
char
*
print_string_ptr
(
const
char
*
str
,
printbuffer
*
p
)
{
const
char
*
ptr
;
char
*
ptr2
;
char
*
out
;
const
char
*
ptr
=
NULL
;
char
*
ptr2
=
NULL
;
char
*
out
=
NULL
;
int
len
=
0
;
int
flag
=
0
;
unsigned
char
token
;
unsigned
char
token
=
'\0'
;
/* empty string */
if
(
!
str
)
...
...
@@ -1012,7 +1012,7 @@ static char *print_value(const cJSON *item, int depth, int fmt, printbuffer *p)
/* Build an array from input text. */
static
const
char
*
parse_array
(
cJSON
*
item
,
const
char
*
value
,
const
char
**
ep
)
{
cJSON
*
child
;
cJSON
*
child
=
NULL
;
if
(
*
value
!=
'['
)
{
/* not an array! */
...
...
@@ -1044,7 +1044,7 @@ static const char *parse_array(cJSON *item,const char *value,const char **ep)
/* loop through the comma separated array elements */
while
(
*
value
==
','
)
{
cJSON
*
new_item
;
cJSON
*
new_item
=
NULL
;
if
(
!
(
new_item
=
cJSON_New_Item
()))
{
/* memory fail */
...
...
@@ -1081,8 +1081,8 @@ static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
{
char
**
entries
;
char
*
out
=
NULL
;
char
*
ptr
;
char
*
ret
;
char
*
ptr
=
NULL
;
char
*
ret
=
NULL
;
int
len
=
5
;
cJSON
*
child
=
item
->
child
;
int
numentries
=
0
;
...
...
@@ -1245,7 +1245,7 @@ static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
/* Build an object from the text. */
static
const
char
*
parse_object
(
cJSON
*
item
,
const
char
*
value
,
const
char
**
ep
)
{
cJSON
*
child
;
cJSON
*
child
=
NULL
;
if
(
*
value
!=
'{'
)
{
/* not an object! */
...
...
@@ -1292,7 +1292,7 @@ static const char *parse_object(cJSON *item, const char *value, const char **ep)
while
(
*
value
==
','
)
{
cJSON
*
new_item
;
cJSON
*
new_item
=
NULL
;
if
(
!
(
new_item
=
cJSON_New_Item
()))
{
/* memory fail */
...
...
@@ -1343,12 +1343,12 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
char
**
entries
=
NULL
;
char
**
names
=
NULL
;
char
*
out
=
NULL
;
char
*
ptr
;
char
*
ret
;
char
*
str
;
char
*
ptr
=
NULL
;
char
*
ret
=
NULL
;
char
*
str
=
NULL
;
int
len
=
7
;
int
i
=
0
;
int
j
;
int
j
=
0
;
cJSON
*
child
=
item
->
child
;
int
numentries
=
0
;
int
fail
=
0
;
...
...
@@ -1979,7 +1979,7 @@ cJSON *cJSON_CreateObject(void)
/* Create Arrays: */
cJSON
*
cJSON_CreateIntArray
(
const
int
*
numbers
,
int
count
)
{
int
i
;
int
i
=
0
;
cJSON
*
n
=
NULL
;
cJSON
*
p
=
NULL
;
cJSON
*
a
=
cJSON_CreateArray
();
...
...
@@ -2007,7 +2007,7 @@ cJSON *cJSON_CreateIntArray(const int *numbers, int count)
cJSON
*
cJSON_CreateFloatArray
(
const
float
*
numbers
,
int
count
)
{
int
i
;
int
i
=
0
;
cJSON
*
n
=
NULL
;
cJSON
*
p
=
NULL
;
cJSON
*
a
=
cJSON_CreateArray
();
...
...
@@ -2035,7 +2035,7 @@ cJSON *cJSON_CreateFloatArray(const float *numbers, int count)
cJSON
*
cJSON_CreateDoubleArray
(
const
double
*
numbers
,
int
count
)
{
int
i
;
int
i
=
0
;
cJSON
*
n
=
NULL
;
cJSON
*
p
=
NULL
;
cJSON
*
a
=
cJSON_CreateArray
();
...
...
@@ -2063,7 +2063,7 @@ cJSON *cJSON_CreateDoubleArray(const double *numbers, int count)
cJSON
*
cJSON_CreateStringArray
(
const
char
**
strings
,
int
count
)
{
int
i
;
int
i
=
0
;
cJSON
*
n
=
NULL
;
cJSON
*
p
=
NULL
;
cJSON
*
a
=
cJSON_CreateArray
();
...
...
@@ -2092,10 +2092,10 @@ cJSON *cJSON_CreateStringArray(const char **strings, int count)
/* Duplication */
cJSON
*
cJSON_Duplicate
(
const
cJSON
*
item
,
int
recurse
)
{
cJSON
*
newitem
;
cJSON
*
cptr
;
cJSON
*
newitem
=
NULL
;
cJSON
*
cptr
=
NULL
;
cJSON
*
nptr
=
NULL
;
cJSON
*
newchild
;
cJSON
*
newchild
=
NULL
;
/* Bail on bad ptr */
if
(
!
item
)
...
...
cJSON_Utils.c
浏览文件 @
b88da9b0
...
...
@@ -6,8 +6,8 @@
static
char
*
cJSONUtils_strdup
(
const
char
*
str
)
{
size_t
len
;
char
*
copy
;
size_t
len
=
0
;
char
*
copy
=
NULL
;
len
=
strlen
(
str
)
+
1
;
if
(
!
(
copy
=
(
char
*
)
malloc
(
len
)))
...
...
@@ -290,7 +290,7 @@ static int cJSONUtils_Compare(cJSON *a, cJSON *b)
b
=
b
->
child
;
while
(
a
&&
b
)
{
int
err
;
int
err
=
0
;
/* compare object keys */
if
(
cJSONUtils_strcasecmp
(
a
->
string
,
b
->
string
))
{
...
...
@@ -475,7 +475,7 @@ static int cJSONUtils_ApplyPatch(cJSON *object, cJSON *patch)
int
cJSONUtils_ApplyPatches
(
cJSON
*
object
,
cJSON
*
patches
)
{
int
err
;
int
err
=
0
;
if
((
patches
->
type
&
0xFF
)
!=
cJSON_Array
)
{
/* malformed patches. */
...
...
@@ -550,7 +550,7 @@ static void cJSONUtils_CompareToPatch(cJSON *patches, const char *path, cJSON *f
case
cJSON_Array
:
{
int
c
;
int
c
=
0
;
char
*
newpath
=
(
char
*
)
malloc
(
strlen
(
path
)
+
23
);
/* Allow space for 64bit int. */
/* generate patches for all array elements that exist in "from" and "to" */
for
(
c
=
0
,
from
=
from
->
child
,
to
=
to
->
child
;
from
&&
to
;
from
=
from
->
next
,
to
=
to
->
next
,
c
++
)
...
...
@@ -575,8 +575,8 @@ static void cJSONUtils_CompareToPatch(cJSON *patches, const char *path, cJSON *f
case
cJSON_Object
:
{
cJSON
*
a
;
cJSON
*
b
;
cJSON
*
a
=
NULL
;
cJSON
*
b
=
NULL
;
cJSONUtils_SortObject
(
from
);
cJSONUtils_SortObject
(
to
);
...
...
test.c
浏览文件 @
b88da9b0
...
...
@@ -27,8 +27,8 @@
/* Parse text to JSON, then render back to text, and print! */
void
doit
(
char
*
text
)
{
char
*
out
;
cJSON
*
json
;
char
*
out
=
NULL
;
cJSON
*
json
=
NULL
;
json
=
cJSON_Parse
(
text
);
if
(
!
json
)
...
...
@@ -47,9 +47,9 @@ void doit(char *text)
/* Read a file, parse, render back, etc. */
void
dofile
(
char
*
filename
)
{
FILE
*
f
;
long
len
;
char
*
data
;
FILE
*
f
=
NULL
;
long
len
=
0
;
char
*
data
=
NULL
;
/* open in read binary mode */
f
=
fopen
(
filename
,
"rb"
);
...
...
@@ -85,13 +85,13 @@ struct record
void
create_objects
(
void
)
{
/* declare a few. */
cJSON
*
root
;
cJSON
*
fmt
;
cJSON
*
img
;
cJSON
*
thm
;
cJSON
*
fld
;
char
*
out
;
int
i
;
cJSON
*
root
=
NULL
;
cJSON
*
fmt
=
NULL
;
cJSON
*
img
=
NULL
;
cJSON
*
thm
=
NULL
;
cJSON
*
fld
=
NULL
;
char
*
out
=
NULL
;
int
i
=
0
;
/* Our "days of the week" array: */
const
char
*
strings
[
7
]
=
...
...
test_utils.c
浏览文件 @
b88da9b0
...
...
@@ -10,9 +10,9 @@ int main(void)
char
*
patchtext
=
NULL
;
char
*
patchedtext
=
NULL
;
int
i
;
int
i
=
0
;
/* JSON Pointer tests: */
cJSON
*
root
;
cJSON
*
root
=
NULL
;
const
char
*
json
=
"{"
"
\"
foo
\"
: [
\"
bar
\"
,
\"
baz
\"
],"
"
\"\"
: 0,"
...
...
@@ -68,8 +68,8 @@ int main(void)
/* Misc tests */
int
numbers
[
10
]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
const
char
*
random
=
"QWERTYUIOPASDFGHJKLZXCVBNM"
;
char
buf
[
2
]
=
{
0
,
0
},
*
before
,
*
after
;
cJSON
*
object
,
*
nums
,
*
num6
,
*
sortme
;
char
buf
[
2
]
=
{
0
,
0
},
*
before
=
NULL
,
*
after
=
NULL
;
cJSON
*
object
=
NULL
,
*
nums
=
NULL
,
*
num6
=
NULL
,
*
sortme
=
NULL
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录