良好做法缺陷
通过这些缺陷,您可以了解良好的编码做法,例如,检测硬编码的内存缓冲区大小或未使用的函数参数
通过这些缺陷,您可以了解良好的编码做法。这些缺陷本身可能不会导致崩溃,但它们有时会帮助突出显示代码中更严重的逻辑错误。这些缺陷还会使代码容易受到攻击且难以维护。这些缺陷包括:
硬编码的常量,例如缓冲区大小和循环边界
妨碍代码可读性的问题
潜在的编码错误
缺失
const
Polyspace 结果
声明语法具有多义性 | Declaration syntax can be interpreted as object declaration or part of function declaration |
缩进不正确的语句 | Statement indentation incorrectly makes it appear as part of a block |
无效的科学记数法格式 | the use of an invalid format makes the code less readable (自 R2022b 起) |
一行包含多条语句 | Multiple statements on a line |
缓冲区大小被硬编码 | Size of memory buffer is a numerical value instead of symbolic constant |
循环边界被硬编码 | Loop boundary is a numerical value instead of symbolic constant |
用于操作内存的对象大小被硬编码 | Memory manipulation with hard-coded size instead of sizeof |
方法不是常量 | A method that can be made const is not marked
const (自 R2022a 起) |
公共静态字段不是常量 | A static and public field of a
struct or class is not marked as a
const (自 R2022a 起) |
未修改的变量未使用 const 进行限定 | Variable not const -qualified but variable value not modified
during lifetime |
switch case 缺失 break | case block of switch statement does not end in a break , [[fallthrough]] or explanatory comment |
switch 表达式的数据类型可能不当 | switch expression has a data type other than char, short, int or
enum |
if、for 或 while 语句行上出现分号 | Semicolon on same line results in empty body of if ,
for or while statement |
删除 void 指针 | delete operates on a void* pointer
pointing to an object |
未重载对应的分配或释放函数 | Only one function in an allocation-deallocation function pair is overloaded |
未对释放的指针进行重置 | Pointer free not followed by a reset statement to clear
leftover data |
由 const 限定类型的 C++ 引用后续被修改 | Reference to const -qualified type is subsequently
modified |
用 const 或 volatile 限定 C++ 引用类型 | Reference type declared with a redundant const or
volatile qualifier |
捕获通用异常的 catch 声明 | A catch block handles a generic exception that might have many
different subtypes (自 R2022a 起) |
抛出通用异常的 throw 声明 | A function throws a generic exception, which might have many subtypes (自 R2022a 起) |
引用未命名的临时文件 | Local reference is declared by using unnamed temporary variable that a function returns by value (自 R2023a 起) |
灵活数组成员大小的语法不正确 | Flexible array member defined with size zero or one |
使用禁止的函数 | Use of function that appears in a blocklist of forbidden functions |
使用禁止的关键字 | Use of keyword that appears in a blocklist of forbidden keywords (自 R2022a 起) |
使用禁止的宏 | Use of macro that appears in a blocklist of forbidden macros (自 R2022b 起) |
使用 setjmp/longjmp | setjmp and longjmp cause
deviation from normal control flow |
对相同数据混合进行按位和算术运算 | Statement with mixed bitwise and arithmetic operations |
文件未编译 | File has a compilation error (自 R2021a 起) |
未使用的参数 | Function prototype has parameters not read or written in function body |
未使用的变量 | Variable defined or declared but not read (自 R2024a 起) |
sizeof 操作数中的无用表达式 | sizeof operand contains expression that is not
evaluated |
无用包含 | An include directive is present but not used (自 R2022b 起) |
无用的捕获 | Lambda captures objects but does not use the objects (自 R2024b 起) |
主题
- Bug Finder Defect Groups
The Bug Finder defect checkers are classified into groups such as data flow, concurrency, numerical, and so on.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)