Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
c9e8a68b
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,发现更多精彩内容 >>
提交
c9e8a68b
编写于
6月 10, 2019
作者:
P
Paweł Malowany
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix clang -Wfloat-equal warning
上级
3c893567
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
26 addition
and
6 deletion
+26
-6
CMakeLists.txt
CMakeLists.txt
+1
-0
Makefile
Makefile
+1
-1
cJSON.c
cJSON.c
+9
-3
cJSON.h
cJSON.h
+5
-0
cJSON_Utils.c
cJSON_Utils.c
+10
-2
未找到文件。
CMakeLists.txt
浏览文件 @
c9e8a68b
...
...
@@ -47,6 +47,7 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS)
-Wmissing-variable-declarations
-Wused-but-marked-unused
-Wswitch-enum
-Wfloat-equal
)
elseif
(
"
${
CMAKE_C_COMPILER_ID
}
"
STREQUAL
"MSVC"
)
# Disable warning c4001 - nonstandard extension 'single line comment' was used
...
...
Makefile
浏览文件 @
c9e8a68b
...
...
@@ -34,7 +34,7 @@ else
CFLAGS
+=
-fstack-protector
endif
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)
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
-Wfloat-equal
$(CFLAGS)
uname
:=
$(
shell
sh
-c
'uname -s 2>/dev/null || echo false'
)
...
...
cJSON.c
浏览文件 @
c9e8a68b
...
...
@@ -480,6 +480,12 @@ static void update_offset(printbuffer * const buffer)
buffer
->
offset
+=
strlen
((
const
char
*
)
buffer_pointer
);
}
/* securely comparison of floating-point variables */
static
cJSON_bool
compare_double
(
double
a
,
double
b
)
{
return
(
fabs
(
a
-
b
)
<=
a
*
CJSON_DOUBLE_PRECIION
);
}
/* Render the number nicely from the given item into a string. */
static
cJSON_bool
print_number
(
const
cJSON
*
const
item
,
printbuffer
*
const
output_buffer
)
{
...
...
@@ -497,7 +503,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
}
/* This checks for NaN and Infinity */
if
(
(
d
*
0
)
!=
0
)
if
(
!
compare_double
(
d
*
0
,
0
)
)
{
length
=
sprintf
((
char
*
)
number_buffer
,
"null"
);
}
...
...
@@ -507,7 +513,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
length
=
sprintf
((
char
*
)
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
((
sscanf
((
char
*
)
number_buffer
,
"%lg"
,
&
test
)
!=
1
)
||
!
compare_double
((
double
)
test
,
d
))
{
/* If not, print with 17 decimal places of precision */
length
=
sprintf
((
char
*
)
number_buffer
,
"%1.17g"
,
d
);
...
...
@@ -2876,7 +2882,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons
return
true
;
case
cJSON_Number
:
if
(
a
->
valuedouble
==
b
->
valuedouble
)
if
(
compare_double
(
a
->
valuedouble
,
b
->
valuedouble
)
)
{
return
true
;
}
...
...
cJSON.h
浏览文件 @
c9e8a68b
...
...
@@ -137,6 +137,11 @@ typedef int cJSON_bool;
#define CJSON_NESTING_LIMIT 1000
#endif
/* Precision of double variables comparison */
#ifndef CJSON_DOUBLE_PRECIION
#define CJSON_DOUBLE_PRECIION .00001
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC
(
const
char
*
)
cJSON_Version
(
void
);
...
...
cJSON_Utils.c
浏览文件 @
c9e8a68b
...
...
@@ -39,6 +39,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <math.h>
#if defined(_MSC_VER)
#pragma warning (pop)
...
...
@@ -105,6 +106,13 @@ static int compare_strings(const unsigned char *string1, const unsigned char *st
return
tolower
(
*
string1
)
-
tolower
(
*
string2
);
}
/* securely comparison of floating-point variables */
static
cJSON_bool
compare_double
(
double
a
,
double
b
)
{
return
(
fabs
(
a
-
b
)
<=
a
*
CJSON_DOUBLE_PRECIION
);
}
/* Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */
static
cJSON_bool
compare_pointers
(
const
unsigned
char
*
name
,
const
unsigned
char
*
pointer
,
const
cJSON_bool
case_sensitive
)
{
...
...
@@ -595,7 +603,7 @@ static cJSON_bool compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensiti
{
case
cJSON_Number
:
/* numeric mismatch. */
if
((
a
->
valueint
!=
b
->
valueint
)
||
(
a
->
valuedouble
!=
b
->
valuedouble
))
if
((
a
->
valueint
!=
b
->
valueint
)
||
(
!
compare_double
(
a
->
valuedouble
,
b
->
valuedouble
)
))
{
return
false
;
}
...
...
@@ -1135,7 +1143,7 @@ static void create_patches(cJSON * const patches, const unsigned char * const pa
switch
(
from
->
type
&
0xFF
)
{
case
cJSON_Number
:
if
((
from
->
valueint
!=
to
->
valueint
)
||
(
from
->
valuedouble
!=
to
->
valuedouble
))
if
((
from
->
valueint
!=
to
->
valueint
)
||
(
compare_double
(
from
->
valuedouble
,
to
->
valuedouble
)
))
{
compose_patch
(
patches
,
(
const
unsigned
char
*
)
"replace"
,
path
,
NULL
,
to
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录