主要内容

本页翻译不是最新的。点击此处可查看最新英文版本。

良好做法缺陷

通过这些缺陷,您可以了解良好的编码做法,例如,检测硬编码的内存缓冲区大小或未使用的函数参数

通过这些缺陷,您可以了解良好的编码做法。这些缺陷本身可能不会导致崩溃,但它们有时会帮助突出显示代码中更严重的逻辑错误。这些缺陷还会使代码容易受到攻击且难以维护。这些缺陷包括:

  • 硬编码的常量,例如缓冲区大小和循环边界

  • 妨碍代码可读性的问题

  • 潜在的编码错误

  • 缺失 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
重复代码A section of code is duplicated in other places (自 R2023a 起)
部分重复代码A section of code is duplicated in other places with very minor changes (自 R2023a 起)
缓冲区大小被硬编码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
以分号终止的宏Macro definition ends with a semicolon
包含多个语句的宏Macro consists of multiple semicolon-terminated statements, enclosed in braces or not
switch case 缺失 breakcase 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/longjmpsetjmp 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.