Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
3d3bfc6a
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,发现更多精彩内容 >>
提交
3d3bfc6a
编写于
2月 03, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Compiler flag -Wconversion
Makes type conversions explicit, if they alter a value
上级
41e2837d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
81 addition
and
43 deletion
+81
-43
CMakeLists.txt
CMakeLists.txt
+1
-1
Makefile
Makefile
+1
-1
cJSON.c
cJSON.c
+67
-35
cJSON_Utils.c
cJSON_Utils.c
+8
-2
test.c
test.c
+4
-4
未找到文件。
CMakeLists.txt
浏览文件 @
3d3bfc6a
...
...
@@ -15,7 +15,7 @@ set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT
option
(
ENABLE_CUSTOM_COMPILER_FLAGS
"Enables custom compiler flags for Clang and GCC"
ON
)
if
(
ENABLE_CUSTOM_COMPILER_FLAGS
)
if
((
"
${
CMAKE_C_COMPILER_ID
}
"
MATCHES
"GNU"
)
OR
(
"
${
CMAKE_C_COMPILER_ID
}
"
MATCHES
"Clang"
))
set
(
CMAKE_C_FLAGS
"
${
CMAKE_C_FLAGS
}
-std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default"
)
set
(
CMAKE_C_FLAGS
"
${
CMAKE_C_FLAGS
}
-std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default
-Wconversion
"
)
endif
()
endif
()
...
...
Makefile
浏览文件 @
3d3bfc6a
...
...
@@ -23,7 +23,7 @@ INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
INSTALL
?=
cp
-a
R_CFLAGS
=
-fPIC
-std
=
c89
-pedantic
-Wall
-Werror
-Wstrict-prototypes
-Wwrite-strings
-Wshadow
-Winit-self
-Wcast-align
-Wformat
=
2
-Wmissing-prototypes
-Wstrict-overflow
=
2
-Wcast-qual
-Wc
++-compat
-Wundef
-Wswitch-default
$(CFLAGS)
R_CFLAGS
=
-fPIC
-std
=
c89
-pedantic
-Wall
-Werror
-Wstrict-prototypes
-Wwrite-strings
-Wshadow
-Winit-self
-Wcast-align
-Wformat
=
2
-Wmissing-prototypes
-Wstrict-overflow
=
2
-Wcast-qual
-Wc
++-compat
-Wundef
-Wswitch-default
-Wconversion
$(CFLAGS)
uname
:=
$(
shell
sh
-c
'uname -s 2>/dev/null || echo false'
)
...
...
cJSON.c
浏览文件 @
3d3bfc6a
...
...
@@ -298,7 +298,7 @@ static unsigned char* ensure(printbuffer *p, size_t needed)
return
NULL
;
}
newsize
=
pow2gt
(
needed
);
newsize
=
(
size_t
)
pow2gt
((
int
)
needed
);
newbuffer
=
(
unsigned
char
*
)
cJSON_malloc
(
newsize
);
if
(
!
newbuffer
)
{
...
...
@@ -410,19 +410,20 @@ static unsigned char *print_number(const cJSON *item, printbuffer *p)
/* parse 4 digit hexadecimal number */
static
unsigned
parse_hex4
(
const
unsigned
char
*
str
)
{
unsigned
h
=
0
;
unsigned
int
h
=
0
;
/* first digit */
if
((
*
str
>=
'0'
)
&&
(
*
str
<=
'9'
))
{
h
+=
(
*
str
)
-
'0'
;
h
+=
(
unsigned
int
)
(
*
str
)
-
'0'
;
}
else
if
((
*
str
>=
'A'
)
&&
(
*
str
<=
'F'
))
{
h
+=
10
+
(
*
str
)
-
'A'
;
h
+=
(
unsigned
int
)
10
+
(
*
str
)
-
'A'
;
}
else
if
((
*
str
>=
'a'
)
&&
(
*
str
<=
'f'
))
{
h
+=
10
+
(
*
str
)
-
'a'
;
h
+=
(
unsigned
int
)
10
+
(
*
str
)
-
'a'
;
}
else
/* invalid */
{
...
...
@@ -435,15 +436,15 @@ static unsigned parse_hex4(const unsigned char *str)
str
++
;
if
((
*
str
>=
'0'
)
&&
(
*
str
<=
'9'
))
{
h
+=
(
*
str
)
-
'0'
;
h
+=
(
unsigned
int
)
(
*
str
)
-
'0'
;
}
else
if
((
*
str
>=
'A'
)
&&
(
*
str
<=
'F'
))
{
h
+=
10
+
(
*
str
)
-
'A'
;
h
+=
(
unsigned
int
)
10
+
(
*
str
)
-
'A'
;
}
else
if
((
*
str
>=
'a'
)
&&
(
*
str
<=
'f'
))
{
h
+=
10
+
(
*
str
)
-
'a'
;
h
+=
(
unsigned
int
)
10
+
(
*
str
)
-
'a'
;
}
else
/* invalid */
{
...
...
@@ -455,15 +456,15 @@ static unsigned parse_hex4(const unsigned char *str)
str
++
;
if
((
*
str
>=
'0'
)
&&
(
*
str
<=
'9'
))
{
h
+=
(
*
str
)
-
'0'
;
h
+=
(
unsigned
int
)
(
*
str
)
-
'0'
;
}
else
if
((
*
str
>=
'A'
)
&&
(
*
str
<=
'F'
))
{
h
+=
10
+
(
*
str
)
-
'A'
;
h
+=
(
unsigned
int
)
10
+
(
*
str
)
-
'A'
;
}
else
if
((
*
str
>=
'a'
)
&&
(
*
str
<=
'f'
))
{
h
+=
10
+
(
*
str
)
-
'a'
;
h
+=
(
unsigned
int
)
10
+
(
*
str
)
-
'a'
;
}
else
/* invalid */
{
...
...
@@ -475,15 +476,15 @@ static unsigned parse_hex4(const unsigned char *str)
str
++
;
if
((
*
str
>=
'0'
)
&&
(
*
str
<=
'9'
))
{
h
+=
(
*
str
)
-
'0'
;
h
+=
(
unsigned
int
)
(
*
str
)
-
'0'
;
}
else
if
((
*
str
>=
'A'
)
&&
(
*
str
<=
'F'
))
{
h
+=
10
+
(
*
str
)
-
'A'
;
h
+=
(
unsigned
int
)
10
+
(
*
str
)
-
'A'
;
}
else
if
((
*
str
>=
'a'
)
&&
(
*
str
<=
'f'
))
{
h
+=
10
+
(
*
str
)
-
'a'
;
h
+=
(
unsigned
int
)
10
+
(
*
str
)
-
'a'
;
}
else
/* invalid */
{
...
...
@@ -650,20 +651,20 @@ static const unsigned char *parse_string(cJSON *item, const unsigned char *str,
switch
(
len
)
{
case
4
:
/* 10xxxxxx */
*--
ptr2
=
((
uc
|
0x80
)
&
0xBF
);
*--
ptr2
=
(
unsigned
char
)(
(
uc
|
0x80
)
&
0xBF
);
uc
>>=
6
;
case
3
:
/* 10xxxxxx */
*--
ptr2
=
((
uc
|
0x80
)
&
0xBF
);
*--
ptr2
=
(
unsigned
char
)(
(
uc
|
0x80
)
&
0xBF
);
uc
>>=
6
;
case
2
:
/* 10xxxxxx */
*--
ptr2
=
((
uc
|
0x80
)
&
0xBF
);
*--
ptr2
=
(
unsigned
char
)(
(
uc
|
0x80
)
&
0xBF
);
uc
>>=
6
;
case
1
:
/* depending on the length in bytes this determines the
* encoding ofthe first UTF8 byte */
*--
ptr2
=
(
u
c
|
firstByteMark
[
len
]
);
*--
ptr2
=
(
u
nsigned
char
)((
uc
|
firstByteMark
[
len
])
&
0xFF
);
default:
*
ep
=
str
;
return
NULL
;
...
...
@@ -728,7 +729,7 @@ static unsigned char *print_string_ptr(const unsigned char *str, printbuffer *p)
/* no characters have to be escaped */
if
(
!
flag
)
{
len
=
ptr
-
str
;
len
=
(
size_t
)(
ptr
-
str
)
;
if
(
p
)
{
out
=
ensure
(
p
,
len
+
3
);
...
...
@@ -917,12 +918,19 @@ char *cJSON_PrintUnformatted(const cJSON *item)
char
*
cJSON_PrintBuffered
(
const
cJSON
*
item
,
int
prebuffer
,
cjbool
fmt
)
{
printbuffer
p
;
p
.
buffer
=
(
unsigned
char
*
)
cJSON_malloc
(
prebuffer
);
if
(
prebuffer
<
0
)
{
return
false
;
}
p
.
buffer
=
(
unsigned
char
*
)
cJSON_malloc
((
size_t
)
prebuffer
);
if
(
!
p
.
buffer
)
{
return
NULL
;
}
p
.
length
=
prebuffer
;
p
.
length
=
(
size_t
)
prebuffer
;
p
.
offset
=
0
;
p
.
noalloc
=
false
;
...
...
@@ -932,11 +940,17 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, cjbool fmt)
int
cJSON_PrintPreallocated
(
cJSON
*
item
,
char
*
buf
,
const
int
len
,
const
cjbool
fmt
)
{
printbuffer
p
;
if
(
len
<
0
)
{
return
false
;
}
p
.
buffer
=
(
unsigned
char
*
)
buf
;
p
.
length
=
len
;
p
.
length
=
(
size_t
)
len
;
p
.
offset
=
0
;
p
.
noalloc
=
true
;
return
print_value
(
item
,
0
,
fmt
,
&
p
)
!=
NULL
;
return
print_value
(
item
,
0
,
fmt
,
&
p
)
!=
NULL
;
}
/* Parser core - when encountering text, process appropriately. */
...
...
@@ -1546,7 +1560,7 @@ static unsigned char *print_object(const cJSON *item, size_t depth, cjbool fmt,
p
->
offset
=
update
(
p
);
/* print comma if not last */
len
=
(
fmt
?
1
:
0
)
+
(
child
->
next
?
1
:
0
);
len
=
(
size_t
)
(
fmt
?
1
:
0
)
+
(
child
->
next
?
1
:
0
);
ptr
=
ensure
(
p
,
len
+
1
);
if
(
!
ptr
)
{
...
...
@@ -1709,7 +1723,7 @@ static unsigned char *print_object(const cJSON *item, size_t depth, cjbool fmt,
}
/* Get Array size/item / object item. */
int
cJSON_GetArraySize
(
const
cJSON
*
array
)
int
cJSON_GetArraySize
(
const
cJSON
*
array
)
{
cJSON
*
c
=
array
->
child
;
size_t
i
=
0
;
...
...
@@ -1721,7 +1735,7 @@ int cJSON_GetArraySize(const cJSON *array)
/* FIXME: Can overflow here. Cannot be fixed without breaking the API */
return
i
;
return
(
int
)
i
;
}
cJSON
*
cJSON_GetArrayItem
(
const
cJSON
*
array
,
int
item
)
...
...
@@ -1843,7 +1857,7 @@ void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *it
cJSON_AddItemToObject
(
object
,
string
,
create_reference
(
item
));
}
cJSON
*
cJSON_DetachItemFromArray
(
cJSON
*
array
,
in
t
which
)
static
cJSON
*
DetachItemFromArray
(
cJSON
*
array
,
size_
t
which
)
{
cJSON
*
c
=
array
->
child
;
while
(
c
&&
(
which
>
0
))
...
...
@@ -1874,6 +1888,15 @@ cJSON *cJSON_DetachItemFromArray(cJSON *array, int which)
return
c
;
}
cJSON
*
cJSON_DetachItemFromArray
(
cJSON
*
array
,
int
which
)
{
if
(
which
<
0
)
{
return
NULL
;
}
return
DetachItemFromArray
(
array
,
(
size_t
)
which
);
}
void
cJSON_DeleteItemFromArray
(
cJSON
*
array
,
int
which
)
{
...
...
@@ -1891,7 +1914,7 @@ cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string)
}
if
(
c
)
{
return
cJSON_
DetachItemFromArray
(
object
,
i
);
return
DetachItemFromArray
(
object
,
i
);
}
return
NULL
;
...
...
@@ -1929,7 +1952,7 @@ void cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
}
}
void
cJSON_ReplaceItemInArray
(
cJSON
*
array
,
in
t
which
,
cJSON
*
newitem
)
static
void
ReplaceItemInArray
(
cJSON
*
array
,
size_
t
which
,
cJSON
*
newitem
)
{
cJSON
*
c
=
array
->
child
;
while
(
c
&&
(
which
>
0
))
...
...
@@ -1958,6 +1981,15 @@ void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem)
c
->
next
=
c
->
prev
=
NULL
;
cJSON_Delete
(
c
);
}
void
cJSON_ReplaceItemInArray
(
cJSON
*
array
,
int
which
,
cJSON
*
newitem
)
{
if
(
which
<
0
)
{
return
;
}
ReplaceItemInArray
(
array
,
(
size_t
)
which
,
newitem
);
}
void
cJSON_ReplaceItemInObject
(
cJSON
*
object
,
const
char
*
string
,
cJSON
*
newitem
)
{
...
...
@@ -1977,7 +2009,7 @@ void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem
}
newitem
->
string
=
(
char
*
)
cJSON_strdup
((
const
unsigned
char
*
)
string
);
cJSON_
ReplaceItemInArray
(
object
,
i
,
newitem
);
ReplaceItemInArray
(
object
,
i
,
newitem
);
}
}
...
...
@@ -2368,21 +2400,21 @@ void cJSON_Minify(char *json)
else
if
(
*
json
==
'\"'
)
{
/* string literals, which are \" sensitive. */
*
into
++
=
*
json
++
;
*
into
++
=
(
unsigned
char
)
*
json
++
;
while
(
*
json
&&
(
*
json
!=
'\"'
))
{
if
(
*
json
==
'\\'
)
{
*
into
++
=
*
json
++
;
*
into
++
=
(
unsigned
char
)
*
json
++
;
}
*
into
++
=
*
json
++
;
*
into
++
=
(
unsigned
char
)
*
json
++
;
}
*
into
++
=
*
json
++
;
*
into
++
=
(
unsigned
char
)
*
json
++
;
}
else
{
/* All other characters. */
*
into
++
=
*
json
++
;
*
into
++
=
(
unsigned
char
)
*
json
++
;
}
}
...
...
cJSON_Utils.c
浏览文件 @
3d3bfc6a
...
...
@@ -2,6 +2,8 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "cJSON_Utils.h"
static
unsigned
char
*
cJSONUtils_strdup
(
const
unsigned
char
*
str
)
...
...
@@ -172,14 +174,18 @@ cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer)
/* parse array index */
while
((
*
pointer
>=
'0'
)
&&
(
*
pointer
<=
'9'
))
{
which
=
(
10
*
which
)
+
(
*
pointer
++
-
'0'
);
which
=
(
10
*
which
)
+
(
size_t
)(
*
pointer
++
-
'0'
);
}
if
(
*
pointer
&&
(
*
pointer
!=
'/'
))
{
/* not end of string or new path token */
return
NULL
;
}
object
=
cJSON_GetArrayItem
(
object
,
which
);
if
(
which
>
INT_MAX
)
{
return
NULL
;
}
object
=
cJSON_GetArrayItem
(
object
,
(
int
)
which
);
}
else
if
((
object
->
type
&
0xFF
)
==
cJSON_Object
)
{
...
...
test.c
浏览文件 @
3d3bfc6a
...
...
@@ -97,8 +97,8 @@ static int print_preallocated(cJSON *root)
char
*
out
=
NULL
;
char
*
buf
=
NULL
;
char
*
buf_fail
=
NULL
;
in
t
len
=
0
;
in
t
len_fail
=
0
;
size_
t
len
=
0
;
size_
t
len_fail
=
0
;
/* formatted print */
out
=
cJSON_Print
(
root
);
...
...
@@ -123,7 +123,7 @@ static int print_preallocated(cJSON *root)
}
/* Print to buffer */
if
(
!
cJSON_PrintPreallocated
(
root
,
buf
,
len
,
1
))
{
if
(
!
cJSON_PrintPreallocated
(
root
,
buf
,
(
int
)
len
,
1
))
{
printf
(
"cJSON_PrintPreallocated failed!
\n
"
);
if
(
strcmp
(
out
,
buf
)
!=
0
)
{
printf
(
"cJSON_PrintPreallocated not the same as cJSON_Print!
\n
"
);
...
...
@@ -140,7 +140,7 @@ static int print_preallocated(cJSON *root)
printf
(
"%s
\n
"
,
buf
);
/* force it to fail */
if
(
cJSON_PrintPreallocated
(
root
,
buf_fail
,
len_fail
,
1
))
{
if
(
cJSON_PrintPreallocated
(
root
,
buf_fail
,
(
int
)
len_fail
,
1
))
{
printf
(
"cJSON_PrintPreallocated failed to show error with insufficient memory!
\n
"
);
printf
(
"cJSON_Print result:
\n
%s
\n
"
,
out
);
printf
(
"cJSON_PrintPreallocated result:
\n
%s
\n
"
,
buf_fail
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录