Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
a3154a36
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,发现更多精彩内容 >>
未验证
提交
a3154a36
编写于
9月 21, 2019
作者:
A
Alanscut
提交者:
GitHub
9月 21, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #388 from singku/secure_c
Replace strcpy with strncpy, sprintf with snprintf
上级
189b51c5
16f56300
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
25 addition
and
18 deletion
+25
-18
cJSON.c
cJSON.c
+25
-18
未找到文件。
cJSON.c
浏览文件 @
a3154a36
...
...
@@ -95,7 +95,7 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) {
CJSON_PUBLIC
(
const
char
*
)
cJSON_Version
(
void
)
{
static
char
version
[
15
];
s
printf
(
version
,
"%i.%i.%i"
,
CJSON_VERSION_MAJOR
,
CJSON_VERSION_MINOR
,
CJSON_VERSION_PATCH
);
s
nprintf
(
version
,
sizeof
(
version
)
,
"%i.%i.%i"
,
CJSON_VERSION_MAJOR
,
CJSON_VERSION_MINOR
,
CJSON_VERSION_PATCH
);
return
version
;
}
...
...
@@ -499,22 +499,22 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
/* This checks for NaN and Infinity */
if
((
d
*
0
)
!=
0
)
{
length
=
s
printf
((
char
*
)
number_buffer
,
"null"
);
length
=
s
nprintf
((
char
*
)
number_buffer
,
sizeof
(
number_buffer
)
,
"null"
);
}
else
{
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
length
=
s
printf
((
char
*
)
number_buffer
,
"%1.15g"
,
d
);
length
=
s
nprintf
((
char
*
)
number_buffer
,
sizeof
(
number_buffer
)
,
"%1.15g"
,
d
);
/* Check whether the original double can be recovered */
if
((
sscanf
((
char
*
)
number_buffer
,
"%lg"
,
&
test
)
!=
1
)
||
((
double
)
test
!=
d
))
{
/* If not, print with 17 decimal places of precision */
length
=
s
printf
((
char
*
)
number_buffer
,
"%1.17g"
,
d
);
length
=
s
nprintf
((
char
*
)
number_buffer
,
sizeof
(
number_buffer
)
,
"%1.17g"
,
d
);
}
}
/* sprintf failed or buffer overrun occurred */
/* s
n
printf failed or buffer overrun occurred */
if
((
length
<
0
)
||
(
length
>
(
int
)(
sizeof
(
number_buffer
)
-
1
)))
{
return
false
;
...
...
@@ -848,15 +848,16 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe
return
false
;
}
const
char
quotes
[]
=
"
\"\"
"
;
/* empty string */
if
(
input
==
NULL
)
{
output
=
ensure
(
output_buffer
,
sizeof
(
"
\"\"
"
));
output
=
ensure
(
output_buffer
,
sizeof
(
quotes
));
if
(
output
==
NULL
)
{
return
false
;
}
str
cpy
((
char
*
)
output
,
"
\"\"
"
);
str
ncpy
((
char
*
)
output
,
quotes
,
output_buffer
->
length
-
output_buffer
->
offset
);
return
true
;
}
...
...
@@ -887,7 +888,7 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe
}
output_length
=
(
size_t
)(
input_pointer
-
input
)
+
escape_characters
;
output
=
ensure
(
output_buffer
,
output_length
+
sizeof
(
"
\"\"
"
));
output
=
ensure
(
output_buffer
,
output_length
+
sizeof
(
quotes
));
if
(
output
==
NULL
)
{
return
false
;
...
...
@@ -943,7 +944,7 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe
break
;
default:
/* escape and print as unicode codepoint */
s
printf
((
char
*
)
output_pointer
,
"u%04x"
,
*
input_pointer
);
s
nprintf
((
char
*
)
output_pointer
,
output_buffer
->
length
-
(
output_pointer
-
output_buffer
->
buffer
)
,
"u%04x"
,
*
input_pointer
);
output_pointer
+=
4
;
break
;
}
...
...
@@ -1286,32 +1287,38 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
switch
((
item
->
type
)
&
0xFF
)
{
case
cJSON_NULL
:
output
=
ensure
(
output_buffer
,
5
);
{
const
char
buff
[]
=
"null"
;
output
=
ensure
(
output_buffer
,
sizeof
(
buff
));
if
(
output
==
NULL
)
{
return
false
;
}
str
cpy
((
char
*
)
output
,
"null"
);
str
ncpy
((
char
*
)
output
,
buff
,
output_buffer
->
length
-
output_buffer
->
offset
);
return
true
;
}
case
cJSON_False
:
output
=
ensure
(
output_buffer
,
6
);
{
const
char
buff
[]
=
"false"
;
output
=
ensure
(
output_buffer
,
sizeof
(
buff
));
if
(
output
==
NULL
)
{
return
false
;
}
str
cpy
((
char
*
)
output
,
"false"
);
str
ncpy
((
char
*
)
output
,
buff
,
output_buffer
->
length
-
output_buffer
->
offset
);
return
true
;
}
case
cJSON_True
:
output
=
ensure
(
output_buffer
,
5
);
{
const
char
buff
[]
=
"true"
;
output
=
ensure
(
output_buffer
,
sizeof
(
buff
));
if
(
output
==
NULL
)
{
return
false
;
}
str
cpy
((
char
*
)
output
,
"true"
);
str
ncpy
((
char
*
)
output
,
buff
,
output_buffer
->
length
-
output_buffer
->
offset
);
return
true
;
}
case
cJSON_Number
:
return
print_number
(
item
,
output_buffer
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录