主要内容

编程缺陷

与编程编码错误相关的缺陷,如赋值与相等运算符、类型不匹配、绕回问题、字符串数组等

这些缺陷是与编程语法相关的错误。这些缺陷包括:

  • 赋值与相等运算符

  • 变量限定符或声明不匹配

  • 格式错误的字符串

Polyspace 结果

全部展开

断言Failed assertion statement
字符值被吸收转化为 EOF数据类型转换使有效的字符值与文件结尾 (EOF) 相同。
声明不匹配Mismatch between function or variable declarations
errno 未重置errno not reset before calling a function that sets errno
不正确的值转发Forwarded object might be modified unexpectedly
无效的迭代器用法Mismatched or uninitialized iterators are used in standard algorithm functions and comparison operations (自 R2022a 起)
无效的 == (相等)运算符使用Equality operation in assignment statement
无效的标准库例程使用Wrong arguments to standard library function
无效的 va_list 参量Variable argument list used after invalidation with va_end or not initialized with va_start or va_copy
误用 errnoerrno incorrectly checked for error conditions
误用窄字符串或宽字符串Narrow (wide) character string passed to wide (narrow) string function
误用不可重入标准函数的返回值Pointer to static buffer from previous call is used despite a subsequent call that modifies the buffer
不符合 AUTOSAR 规范An RTE API function is used with arguments that violate the AUTOSAR standard specification (自 R2021a 起)
指向销毁的临时对象的指针或引用Destruction of temporary object results in dangling pointer or reference (自 R2023b 起)
可能的 sizeof 误用Use of sizeof operator can cause unintended results
运算符优先级规则导致可能的非预期表达式计算Operator precedence rules cause unexpected evaluation order in arithmetic expression
用悬空指针初始化 std::string_viewAn std::string_view object is initialized by using an unnamed temporary object (自 R2022b 起)
Typedef 不匹配Mismatch between typedef statements
大小不为正数的可变长度数组Size of variable-length array is zero or negative
写入 const 限定对象Object declared with a const qualifier is modified
在 sizeof 中使用了错误的类型sizeof argument does not match pointed type
退出处理程序异常终止Exit handler function interrupts the normal execution of a program
错误的文件访问模式或状态Access mode argument of function in fopen or open group is invalid
通过非原型函数指针进行调用Function pointer declared without its type or number of parameters causes unexpected behavior
内存重叠的复制Source and destination arguments of a copy function have overlapping memory
环境指针因前面的运算而失效Call to setenv or putenv family function modifies environment pointed to by pointer
使用相等运算符进行浮点比较Imprecise comparison of floating-point variables
从信号处理程序调用的函数不是异步安全的Call to interrupted function causes undefined program behavior
从信号处理程序调用的函数不是异步安全的(严格 ISO C)Call to interrupted function causes undefined program behavior
不正确的数组初始化Incorrect array initialization when using initializers
不正确的 erase-remove 惯用法Container's erase() is not called or called improperly following a call to std::remove() (自 R2022a 起)
传递给 va_arg 的数据类型不正确Data type of variadic function argument does not match type in va_arg call
不正确的指针缩放Implicit scaling in pointer arithmetic might be ignored
向 va_start 传递不正确的类型数据Data type of second argument to va_start macro leads to undefined behavior
在 C++ 中不正确地使用 offsetofIncorrect arguments to offsetof macro causes undefined behavior
不正确地使用 va_startva_start is called in a non-variadic function or called with a second argument that is not the rightmost parameter of a variadic function
未遵守内联约束Non-const static variable is modified in nonstatic inline function
无效的内存组织假设Address is computed by adding or subtracting from address of a variable
无效的文件位置fsetpos() is invoked with a file position argument not obtained from fgetpos()
无效的 = 运算符使用Assignment in conditional statement
比较填充数据内存memcmp compares data stored in structure padding
比较字符串内存memcmp compares data stored in strings after the null terminator
传输数据时未对字节重新排序Different endianness of host and network
在信号处理程序中误用 errnoYou read errno after calling an errno-setting function in a signal handler
在信号处理程序内访问共享数据Access or modification of shared data causes inconsistent state
不安全的宏中带副作用的参量Macro contains arguments that can be evaluated multiple times or not evaluated
从信号处理程序内部调用 signalNonpersistent signal handler calling signal() in Windows system causes race condition
用不正确的参量调用标准函数Argument to a standard function does not meet requirements for use in the function
va_arg 调用次数相对当前参量列表太多Number of calls to va_arg exceeds number of arguments passed to variadic function
va_arg 调用次数相对当前参量列表太多Number of calls to va_arg exceeds number of arguments passed to variadic function
头文件中未命名的命名空间Header file contains unnamed namespace leading to multiple definitions
指针和整数之间的不安全转换Misaligned or invalid results from conversions between pointer and integer types
使用大小参量为零的 memsetSize argument of function in memset family is zero
使用不确定字符串Use of unvalidated buffer from fgets-family function
移动后读取变量A variable in a moved-from state is used in an operation that has preconditions (自 R2025a 起)
访问具有临时存在时间的对象Read or write operations on the object are undefined behavior
从文件流中交替执行输入和输出运算间未执行刷新和定位调用Undefined behavior for input or output stream operations
使用非预期值调用 memsetmemset or wmemset used with possibly incorrect arguments
格式字符串设定符和参量不匹配Format specifiers in printf-like functions do not match corresponding arguments
比较浮点值内存Object representation of floating-point values can be different (same) for equal (not equal) floating-point values
字符串数组中缺失 nullString does not terminate with null character
误用 FILE 对象Use of copy of FILE object
误用符号扩展字符值Data type conversion with sign extension causes unexpected behavior
误用具有灵活数组成员的结构体Memory allocation ignores flexible array member
修改了从不可重入标准函数返回的内部缓冲区Function attempts to modify internal buffer returned from a nonreentrant standard function
重叠赋值Memory overlap between left and right sides of an assignment
可能发生复制粘贴错误A section of code is duplicated in other places with exactly one minor change (自 R2023a 起)
预定义宏用作对象You use standard library macros such as assert and errno as objects
在宏参量中使用预处理器指令You use a preprocessor directive in the argument to a function-like macro
在转换中删除限定符Variable qualifier is lost during conversion
将 string::c_str() 结果与另一个指针做比较The C string obtained from std::string::c_str() is compared to a pointer (or NULL) (自 R2021b 起)
从计算异常信号处理程序返回结果Undefined behavior when signal handler returns normally from program error
表达式的副作用被忽略sizeof, _Alignof, or _Generic operates on expression with side effect
可能带非预期副作用的流参量Stream argument side effects occur more than once
通过标记串联创建通用字符名称You create a universal character name by joining tokens with ## operator
从字符串到数值的不安全转换String to number conversion without validation checks

主题