Skip to content

Commit

Permalink
修正引用
Browse files Browse the repository at this point in the history
ID_illFloatComparison 应与 CWE-1077 关联
  • Loading branch information
brotherbeer authored Sep 30, 2024
1 parent d85aca8 commit 66c555a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions c-cpp-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@
"level": "warning",
"comment": "用 == 或 != 判断浮点数(float、double、long double)是否相等会得到非预期的结果。",
"tag": "expression",
"reference": "CWE-1025,MISRA C 2004 13.3,MISRA C++ 2008 6-2-2"
"reference": "CWE-1077,MISRA C 2004 13.3,MISRA C++ 2008 6-2-2"
},
"ID_successiveComparison": {
"checkPoint": "比较运算不可作为另一个比较运算的直接子表达式",
Expand Down Expand Up @@ -3647,7 +3647,7 @@
"ID_bufferOverflow": {
"checkPoint": "避免缓冲区溢出",
"level": "warning",
"comment": "缓冲区溢出是一种高度危险的安全漏洞,广泛存在于各类软件系统中",
"comment": "缓冲区溢出是一种高度危险的安全漏洞,而且广泛存在于各类软件系统中",
"tag": "buffer",
"related": "ID_arrayIndexOverflow,ID_unsafeStringFunction",
"reference": "CWE-119,CWE-125,CWE-787,CWE-788"
Expand Down
14 changes: 7 additions & 7 deletions c-cpp-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4912,8 +4912,8 @@ namespace NS {
void foo(short);
}

using namespace NS; // Non-compliant
using namespace std; // Non-compliant
using namespace NS; // Non-compliant, a using-directive in a header
using namespace std; // Non-compliant, a using-directive in a header
```
下例展示的问题是头文件不同的包含顺序竟导致同一函数产生了不同的行为:
```
Expand Down Expand Up @@ -5343,8 +5343,8 @@ void foo() {
建议用 using 声明 代替 using 指令:
```
void foo() {
using myspace::type; // Compliant
using myspace::some_fun; // Compliant
using myspace::type; // Compliant, using-declaration
using myspace::some_fun; // Compliant, using-declaration

type x;
some_fun(x);
Expand Down Expand Up @@ -18431,12 +18431,12 @@ if (feq(f, 0.1)) { // Compliant
cout << "OK";
}
```
在实际代码中,对于 float、double、long double 等不同的浮点类型,可以分别使用在标准头文件 float.h 中定义的宏 FLT\_EPSILON、DBL\_EPSILON、LDBL\_EPSILON 作为 e 的值,在 C\+\+ 代码中,也可以使用标准模板库提供的 std::numeric\_limits\<T\>::epsilon(),其中 T 为浮点类型
在实际代码中,对于 float、double、long double 等不同的浮点类型,可以分别使用在标准头文件 float.h 中定义的宏 FLT\_EPSILON、DBL\_EPSILON、LDBL\_EPSILON 作为 e 的值,在 C\+\+ 代码中,也可以使用标准模板库提供的 std::numeric\_limits\<T\>::epsilon(),其中 T 为指定的浮点类型
<br/>
<br/>

#### 参考
CWE-1025
CWE-1077
MISRA C 2004 13.3
MISRA C++ 2008 6-2-2
<br/>
Expand Down Expand Up @@ -21675,7 +21675,7 @@ ID_bufferOverflow &emsp;&emsp;&emsp;&emsp;&nbsp; :fire: buffer warning

<hr/>

缓冲区溢出是一种高度危险的安全漏洞,广泛存在于各类软件系统中
缓冲区溢出是一种高度危险的安全漏洞,而且广泛存在于各类软件系统中

“缓冲区(buffer)”的本意是指内存等高速设备上的区域,程序在这种区域内接收或处理数据,之后再一并输出到网络或磁盘等低速环境,起到提高效率的作用,故称缓冲区。连续的内存区域均可称为缓冲区,在 C/C\+\+ 语言中对应数组等结构。

Expand Down

0 comments on commit 66c555a

Please sign in to comment.