代码缺陷检测规则知识库
文档说明
本知识库面向开源社区三维基础几何引擎的代码缺陷检测场景,整理了项目平台所采用的 Cppcheck 静态分析工具的严重级别体系、检查项(error id)分类、与 CWE 的对应关系,以及对应的违规知识条目。§3(速查表)与 §5.2(标准条目)收录全部 342 项代码缺陷检查规则;§5.3 另对高频重点检查给出深度解析(成因/示例/修复/案例)。
检测器边界:
cppcheck是静态分析工具,强调低误报(宁可漏报也不轻易报错),与编译器告警(-Wall)和clang-tidy互补而非替代。它不需要完整编译环境即可分析,但提供--project=compile_commands.json后分析更准确。本文聚焦通用 C/C++ 缺陷检测,是缺陷检测维度的主干。
规则结构概览
| 严重级别(severity) | 含义 | 代表 error id | 条目数 | --enable 归属 |
|---|---|---|---|---|
| error | 执行时必然为未定义行为/泄漏等错误 | nullPointer、arrayIndexOutOfBounds、memleak、doubleFree、mismatchAllocDealloc | 93 | 默认开启 |
| warning | 执行时可能为未定义行为 | uninitMemberVar、nullPointerRedundantCheck、missingReturn | 110 | --enable=warning |
| style | 风格/冗余/常量性/可疑写法 | unusedVariable、redundantAssignment、cstyleCast、constParameter | 95 | --enable=style |
| performance | 运行时性能建议 | passedByValue、useInitializationList、stlSize | 19 | --enable=performance |
| portability | 可移植性/实现定义行为/64 位 | pointerSize、memsetFloat、AssignmentIntegerToAddress | 20 | --enable=portability |
| information | 配置类信息(非语法错误) | missingInclude、toomanyconfigs、checkersReport | 5 | --enable=information |
| 合计 | 代码缺陷检查规则 | — | 342 | --enable=all(含全部,外加 unusedFunction) |
上表为各严重级别的规则条目数;逐条清单见 §3,深度知识条目见 §5。
目录
- 1 工具链与流水线
- 2 严重级别体系与
--enable - 3 全部检查项清单
- 4 附加能力(MISRA/规则文件/抑制/CWE)
- 5 标准知识条目列表
1 工具链与流水线
| 环节 | 命令(示例) | 说明 |
|---|---|---|
| 全量分析 | cppcheck --enable=all --inconclusive --std=c++17 --project=compile_commands.json | 以编译数据库为输入,覆盖全部宏分支 |
| CI 失败门禁 | cppcheck --enable=warning,style,performance,portability --error-exitcode=1 ... | 命中即非零退出,阻断流水线 |
| 机器可读输出 | --xml --xml-version=2 2> cppcheck.xml | 供看板/SonarQube 摄取 |
| 增量分析 | --cppcheck-build-dir=.cppcheck-cache | 缓存结果,加速重复扫描 |
| 抑制误报 | --suppress=<id>:<file>:<line> 或 --suppressions-list=suppr.txt | 集中管理已知误报 |
| 查看检查说明 | cppcheck --doc | 列出各检查项的文档说明 |
- 唯一事实来源:仓库内
.cppcheck/cppcheck.cfg、suppressions.txt与 CI 调用参数共同固定,本地与 CI 一致。 - 日志特征统一格式:
<file>:<line>:<col>: <severity>: <message> [<errorId>],方括号内即规则编号,可直接映射本文条目。
2 严重级别体系与 --enable
| 级别 | 是否默认开启 | 作为门禁建议 | 说明 |
|---|---|---|---|
| error | 是 | 必须阻断 | 真实缺陷,几乎无误报容忍 |
| warning | --enable=warning | 建议阻断 | 潜在未定义行为 |
| style | --enable=style | 建议阻断(可分级) | 冗余/常量性/可疑写法 |
| performance | --enable=performance | 提示或阻断 | 性能改进建议 |
| portability | --enable=portability | 跨平台项目建议阻断 | 实现定义行为/64 位 |
| information | --enable=information | 仅提示 | 配置类信息(如缺少 include 导致分析不全) |
unusedFunction | 仅 --enable=all 或单独指定 | 提示 | 需全程序视角,单文件不报 |
检查级别(check level):新版
cppcheck引入--check-level=normal|exhaustive。exhaustive启用更深的数据流(ValueFlow)分析,发现更多 error/warning,但更耗时;CI 夜间构建可用exhaustive,PR 快检用normal。
3 全部检查项清单
下表为代码缺陷检查规则清单,按严重级别分组。
说明:此处为通用缺陷检查规则;
--addon引入的 MISRA / CERT / y2038 等编码规范规则不在此列,另见 §4。各 Error ID 的深度知识条目(成因/案例/修复)见 §5。
代码缺陷检查规则列表,共 342 项,按严重级别分组。Error ID 即检测日志方括号内的标识;CWE 为对应弱点编号(部分项无 CWE)。
| 严重级别 | 条目数 |
|---|---|
| error(错误) | 93 |
| warning(警告) | 110 |
| style(风格) | 95 |
| performance(性能) | 19 |
| portability(可移植性) | 20 |
| information(信息) | 5 |
| 合计 | 342 |
error(错误)(93 项)
| Error ID | CWE | 说明(cppcheck 原始消息) |
|---|---|---|
arrayIndexOutOfBounds | 788 | Array 'arr[16]' accessed at index 16, which is out of bounds. |
assignBoolToPointer | 587 | Boolean value assigned to pointer. |
autoVariables | 562 | Address of local auto-variable assigned to a function parameter. |
autovarInvalidDeallocation | 590 | Deallocation of an auto-variable results in undefined behaviour. |
bufferAccessOutOfBounds | 788 | Buffer is accessed out of bounds: buf |
comparePointers | 758 | Comparing pointers that point to different objects |
containerOutOfBounds | 398 | Out of bounds access in expression 'container[x]' |
containerOutOfBoundsIndexExpression | 398 | Out of bounds access of var, index 'var.size()' is out of bounds. |
coutCerrMisusage | 398 | Invalid usage of output stream: '<< std::cout'. |
danglingLifetime | 562 | Non-local variable 'x' will use object. |
danglingReference | 562 | Non-local reference variable 'x' to local variable 'y' |
danglingTemporaryLifetime | 562 | Using object that is a temporary. |
danglingTempReference | 562 | Using reference to dangling temporary. |
deallocret | 672 | Returning/dereferencing 'p' after it is deallocated / released |
deallocuse | 416 | Dereferencing 'varname' after it is deallocated / released |
doubleFree | 415 | Memory pointed to by 'varname' is freed twice. |
eraseDereference | 664 | Invalid iterator 'iter' used. |
eraseIteratorOutOfBounds | 628 | Calling function 'erase()' on the iterator 'iter' which is out of bounds. |
floatConversionOverflow | 190 | Undefined behaviour: float (1e+100) to integer conversion overflow. |
includeNestedTooDeeply | — | message |
integerOverflow | 190 | Signed integer overflow for expression ''. |
invalidContainer | 664 | Using object that may be invalid. |
invalidContainerLoop | 664 | Calling 'erase' while iterating the container is invalid. |
invalidContainerReference | 664 | Reference to x that may be invalid. |
invalidFree | — | Mismatching address is freed. The address you get from malloc() must be freed without offset. |
invalidFunctionArg | 628 | Invalid func_name() argument nr 1. The value is 0 or 1 (boolean) but the valid values are '1:4'. |
invalidFunctionArgBool | 628 | Invalid func_name() argument nr 1. A non-boolean value is required. |
invalidFunctionArgStr | 628 | Invalid func_name() argument nr 1. A nul-terminated string is required. |
invalidIterator1 | 664 | Invalid iterator: iterator |
invalidLifetime | 562 | Using object that is out of scope. |
invalidScanfFormatWidth | 687 | Width 5 given in format string (no. 10) is larger than destination buffer '[0]', use %-1s to prevent overflowing it. |
invalidSuppression | — | message |
IOWithoutPositioning | 664 | Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. |
iterators1 | 664 | Same iterator is used with different containers 'container1' and 'container2'. |
iterators3 | 664 | Same iterator is used with containers 'container' that are temporaries or defined in different scopes. |
leakNoVarFunctionCall | 772 | Allocation with funcName, funcName doesn't release it. |
leakReturnValNotUsed | 771 | Return value of allocation function 'funcName' is not stored. |
mallocOnClassError | 665 | Memory for class instance allocated with malloc(), but class contains a std::string. |
memleak | 401 | Memory leak: varname |
memleakOnRealloc | 401 | Common realloc mistake: 'varname' nulled but not freed upon failure |
memsetClass | 762 | Using 'memfunc' on class that contains a classname. |
memsetClassReference | 665 | Using 'memfunc' on class that contains a reference. |
mismatchAllocDealloc | 762 | Mismatching allocation and deallocation: varname |
mismatchingContainerIterator | 664 | Iterator 'it' referring to container 'v2' is used with container 'v1'. |
mismatchingContainers | 664 | Iterators of different containers 'v1' and 'v2' are used together. |
missingFile | — | message |
missingIncludeExplicit | — | message |
missingReturn | 758 | Found an exit path from function with non-void return type that has missing return statement |
negativeArraySize | 758 | Declaration of array '' with negative size is undefined behaviour |
negativeIndex | 786 | Negative array index |
negativeMemoryAllocationSize | 131 | Memory allocation size is negative. |
nullPointer | 476 | Null pointer dereference |
nullPointerArithmetic | 682 | Pointer arithmetic with NULL pointer. |
objectIndex | 758 | The address of variable '' is accessed at non-zero index. |
operatorEqMissingReturnStatement | 398 | No 'return' statement in non-void function causes undefined behavior. |
overlappingWriteFunction | — | Overlapping read/write in funcname() is undefined behavior |
overlappingWriteUnion | — | Overlapping read/write of union is undefined behavior |
pointerArithBool | 571 | Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. |
preprocessorErrorDirective | — | message |
raceAfterInterlockedDecrement | 362 | Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. |
readWriteOnlyFile | 664 | Read operation on a file that was opened only for writing. |
resourceLeak | 775 | Resource leak: varname |
rethrowNoCurrentException | 480 | Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow. If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object |
returnDanglingLifetime | 562 | Returning object that will be invalid when returning. |
returnReference | 562 | Reference to local variable returned. |
returnTempReference | 562 | Reference to temporary returned. |
selfInitialization | 665 | Member variable 'var' is initialized by itself. |
shiftNegative | 758 | Shifting by a negative value is undefined behaviour |
shiftTooManyBits | 758 | Shifting 32-bit value by 40 bits is undefined behaviour |
shiftTooManyBitsSigned | 758 | Shifting signed 32-bit value by 31 bits is undefined behaviour |
sprintfOverlappingData | 628 | Undefined behavior: Variable 'varname' is used as parameter and destination in s[n]printf(). |
stlBoundaries | 664 | Dangerous comparison using operator< on iterator. |
stlcstr | 664 | Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. |
stlcstrthrow | — | Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. |
stlOutOfBounds | 788 | When i==foo.size(), foo[i] is out of bounds. |
stringLiteralWrite | 758 | Modifying string literal directly or indirectly is undefined behaviour. |
strPlusChar | 665 | Unusual pointer arithmetic. A value of type 'char' is added to a string literal. |
syntaxError | — | message |
throwInEntryPoint | 398 | Unhandled exception thrown in function that is an entry point. |
throwInNoexceptFunction | 398 | Unhandled exception thrown in function declared not to throw exceptions. |
unhandledChar | — | message |
uninitdata | 457 | Memory is allocated but not initialized: varname |
uninitStructMember | 457 | Uninitialized struct member: a.b |
unknownEvaluationOrder | 768 | Expression 'x = x++;' depends on order of evaluation of side effects |
useClosedFile | 910 | Used file that is not opened. |
va_end_missing | 664 | va_list 'vl' was opened but not closed by va_end(). |
va_list_usedBeforeStarted | 664 | va_list 'vl' used before va_start() was called. |
va_start_referencePassed | 758 | Using reference 'arg1' as parameter for va_start() results in undefined behaviour. |
va_start_subsequentCalls | 664 | va_start() or va_copy() called subsequently on 'vl' without va_end() in between. |
virtualDestructor | 404 | Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. |
writeReadOnlyFile | 664 | Write operation on a file that was opened only for reading. |
wrongPrintfScanfArgNum | 685 | printf format string requires 3 parameters but only 2 are given. |
zerodiv | 369 | Division by zero. |
warning(警告)(110 项)
| Error ID | CWE | 说明(cppcheck 原始消息) |
|---|---|---|
accessForwarded | 672 | Access of forwarded variable 'v'. |
accessMoved | 672 | Access of moved variable 'v'. |
argumentSize | 398 | Buffer 'buffer' is too small, the function 'function' expects a bigger buffer in 2nd argument |
arrayIndexOutOfBoundsCond | 788 | Array 'arr[16]' accessed at index 16, which is out of bounds. |
assertWithSideEffect | 398 | Assert statement calls a function which may have desired side effects: 'function'. |
assignmentInAssert | 398 | Assert statement modifies 'var'. |
badBitmaskCheck | 571 | Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? |
charBitOp | 398 | When using 'char' variables in bit operations, sign extension can generate unexpected results. |
charLiteralWithCharPtrCompare | 595 | Char literal compared with pointer 'foo'. Did you intend to dereference it? |
checkCastIntToCharAndBack | 197 | Storing func_name() return value in char variable and then comparing with EOF. |
clarifyStatement | 783 | In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? |
compareBoolExpressionWithInt | 398 | Comparison of a boolean expression with an integer other than 0 or 1. |
comparisonFunctionIsAlwaysTrueOrFalse | 570 | Comparison of two identical variables with isless(varName,varName) always evaluates to false. |
comparisonOfBoolWithInvalidComparator | — | Comparison of a boolean value using relational operator (<, >, <= or >=). |
constStatement | 398 | Redundant code: Found a statement that begins with type constant. |
copyCtorAndEqOperator | — | The class 'class' has 'operator=' but lack of 'copy constructor'. |
copyCtorPointerCopying | 398 | Value of pointer 'var', which points to allocated memory, is copied in copy constructor instead of allocating new memory. |
dangerousTypeCast | 398 | Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast |
derefInvalidIterator | 825 | Possible dereference of an invalid iterator: i |
divideSizeof | 682 | Division of result of sizeof() on pointer type. |
duplInheritedMember | 398 | The class 'class' defines member variable with name 'variable' also defined in its parent class 'class'. |
eraseIteratorOutOfBoundsCond | 628 | Either the condition 'x' is redundant or function 'erase()' is called on the iterator 'iter' which is out of bounds. |
exceptDeallocThrow | 398 | Exception thrown in invalid state, 'p' points at deallocated memory. |
exceptThrowInDestructor | 398 | Class Class is not safe, destructor throws exception |
fcloseInLoopCondition | 910 | fclose() used as loop condition may skip loop body or double-close file handle. |
funcArgOrderDifferent | 683 | Function 'function' argument order different: declaration '' definition '' |
globalLockGuard | 833 | Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. |
identicalConditionAfterEarlyExit | 398 | Identical condition 'x', second condition is always false |
identicalInnerCondition | 398 | Identical inner 'if' condition is always true. |
ignoredReturnValue | 252 | Return value of function malloc() is not used. |
incompatibleFileOpen | 664 | The file 'tmp' is opened for read and write access at the same time on different streams |
incompleteArrayFill | 131 | Array 'buffer' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*buffer)'? |
incorrectCharBooleanError | 571 | Conversion of char literal 'x' to bool always evaluates to true. |
incorrectLogicOperator | 571 | Logical disjunction always evaluates to true: foo > 3 && foo < 4. |
incorrectStringBooleanError | 571 | Conversion of string literal "Hello World" to bool always evaluates to true. |
incorrectStringCompare | 570 | String literal "Hello World" doesn't match length argument for substr(). |
invalidLengthModifierError | 704 | 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. |
invalidPrintfArgType_float | 686 | %f in format string (no. 1) requires 'double' but the argument type is Unknown. |
invalidPrintfArgType_n | 686 | %n in format string (no. 1) requires 'int *' but the argument type is Unknown. |
invalidPrintfArgType_p | 686 | %p in format string (no. 1) requires an address but the argument type is Unknown. |
invalidPrintfArgType_s | 686 | %s in format string (no. 1) requires 'char *' but the argument type is Unknown. |
invalidPrintfArgType_sint | 686 | %i in format string (no. 1) requires 'int' but the argument type is Unknown. |
invalidPrintfArgType_uint | 686 | %u in format string (no. 1) requires 'unsigned int' but the argument type is Unknown. |
invalidscanf | 119 | scanf() without field width limits can crash with huge input data. |
invalidScanfArgType_float | 686 | %f in format string (no. 1) requires 'float *' but the argument type is Unknown. |
invalidScanfArgType_int | 686 | %d in format string (no. 1) requires 'int *' but the argument type is Unknown. |
invalidScanfArgType_s | 686 | %s in format string (no. 1) requires a 'char *' but the argument type is Unknown. |
invalidScanfFormatWidth_smaller | — | Width -1 given in format string (no. 99) is smaller than destination buffer '[0]'. |
invalidTestForOverflow | 391 | Invalid test for overflow 'x + c < x'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. |
leakUnsafeArgAlloc | 401 | Unsafe allocation. If funcName() throws, memory could be leaked. Use make_shared<int>() instead. |
literalWithCharPtrCompare | 595 | String literal compared with variable 'foo'. Did you intend to use strcmp() instead? |
localMutex | 667 | The lock is ineffective because the mutex is locked at the same scope as the mutex itself. |
mallocOnClassWarning | 762 | Memory for class instance allocated with malloc(), but class provides constructors. |
memsetValueOutOfRange | 686 | The 2nd memset() argument 'varname' doesn't fit into an 'unsigned char'. |
memsetZeroBytes | 687 | memset() called to fill 0 bytes. |
mismatchingContainerExpression | 664 | Iterators to containers from different expressions 'v1' and 'v2' are used together. |
missingMemberCopy | 398 | Member variable 'classname::varnamepriv' is not assigned in the move constructor. Should it be moved? |
moduloAlwaysTrueFalse | 398 | Comparison of modulo result is predetermined, because it is always less than 1. |
multiplySizeof | 682 | Multiplying sizeof() with sizeof() indicates a logic error. |
negativeContainerIndex | 786 | Array index -1 is out of bounds. |
noCopyConstructor | 398 | Class 'class' does not have a copy constructor which is recommended since it has dynamic memory/resource management. |
noDestructor | 398 | Class 'class' does not have a destructor which is recommended since it has dynamic memory/resource management. |
noOperatorEq | 398 | Class 'class' does not have a operator= which is recommended since it has dynamic memory/resource management. |
nullPointerArithmeticRedundantCheck | 682 | Either the condition is redundant or there is pointer arithmetic with NULL pointer. |
nullPointerDefaultArg | 476 | Possible null pointer dereference if the default parameter value is used: pointer |
nullPointerOutOfMemory | 476 | Null pointer dereference |
nullPointerOutOfResources | 476 | Null pointer dereference |
nullPointerRedundantCheck | 476 | Either the condition is redundant or there is possible null pointer dereference: pointer. |
operatorEqToSelf | 398 | 'operator=' should check for assignment to self to avoid problems with dynamic memory. |
operatorEqVarError | 398 | Member variable 'classname::' is not assigned a value in 'classname::operator='. |
oppositeInnerCondition | 398 | Opposite inner 'if' condition leads to a dead code block. |
overlappingInnerCondition | 398 | Overlapping inner 'if' condition is always true. |
overlappingStrcmp | — | The expression 'strcmp(x,"def") != 0' is suspicious. It overlaps 'strcmp(x,"abc") == 0'. |
pointerAdditionResultNotNull | — | Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. |
pointerSize | 467 | Size of pointer 'varname' used instead of size of its data. |
publicAllocationError | 398 | Possible leak in public function. The pointer 'varname' is not deallocated before it is allocated. |
pureVirtualCall | — | Call of pure virtual function 'f' in constructor. |
seekOnAppendedFile | 398 | Repositioning operation performed on a file opened in append mode has no effect. |
signConversion | 195 | Expression 'var' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. |
signedCharArrayIndex | 128 | Signed 'char' type used as array index. |
sizeofCalculation | 682 | Found calculation inside sizeof(). |
sizeofDivisionMemfunc | 682 | Division by result of sizeof(). memset() expects a size in bytes, did you intend to multiply instead? |
sizeofFunctionCall | 682 | Found function call inside sizeof(). |
sizeofsizeof | 682 | Calling 'sizeof' on 'sizeof'. |
sizeofwithnumericparameter | 682 | Suspicious usage of 'sizeof' with a numeric constant as parameter. |
sizeofwithsilentarraypointer | 467 | Using 'sizeof' on array given as function argument returns size of a pointer. |
staticStringCompare | 570 | Unnecessary comparison of static strings. |
stlIfFind | 398 | Suspicious condition. The result of find() is an iterator, but it is not properly checked. |
StlMissingComparison | 834 | Missing bounds check for extra iterator increment in loop. |
stringCompare | 571 | Comparison of identical string variables. |
suspiciousCase | 398 | Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. |
suspiciousSemicolon | 398 | Suspicious use of ; at the end of '' statement. |
terminateStrncpy | 170 | The buffer 'var_name' may not be null-terminated after the call to strncpy(). |
thisSubtraction | 398 | Suspicious pointer subtraction. Did you intend to write '->'? |
thisUseAfterFree | — | Using member 'x' when 'this' might be invalid |
uninitDerivedMemberVar | 398 | Member variable 'classname::varname' is not initialized in the constructor. Maybe it should be initialized directly in the class classname? |
uninitDerivedMemberVarPrivate | 398 | Member variable 'classname::varnamepriv' is not initialized in the constructor. Maybe it should be initialized directly in the class classname? |
uninitMemberVar | 398 | Member variable 'classname::varname' is not initialized in the constructor. |
uninitMemberVarPrivate | 398 | Member variable 'classname::varnamepriv' is not initialized in the constructor. |
unsafeClassRefMember | — | Unsafe class: The const reference member 'UnsafeClass::var' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. |
unusedLabelSwitch | 398 | Label '' is not used. Should this be a 'case' of the enclosing switch()? |
unusedLabelSwitchConfiguration | 398 | Label '' is not used. There is #if in function body so the label might be used in code that is removed by the preprocessor. Should this be a 'case' of the enclosing switch()? |
uselessAssignmentPtrArg | 398 | Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? |
uselessCallsCompare | 628 | It is inefficient to call 'str.find(str)' as it always returns 0. |
uselessCallsEmpty | 398 | Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? |
uselessCallsRemove | 762 | Return value of std::remove() ignored. Elements remain in container. |
va_start_wrongParameter | 688 | 'arg1' given to va_start() is not last named argument of the function. Did you intend to pass 'arg2'? |
wrongmathcall | 758 | Passing value '#' to #() leads to implementation-defined result. |
wrongPrintfScanfParameterPositionError | 685 | printf: referencing parameter 2 while 1 arguments given |
zerodivcond | 369 | Either the condition is redundant or there is division by zero. |
style(风格)(95 项)
| Error ID | CWE | 说明(cppcheck 原始消息) |
|---|---|---|
arrayIndexThenCheck | 398 | Array index 'i' is used before limits check. |
assignBoolToFloat | 704 | Boolean value assigned to floating point variable. |
assignIfError | 398 | Mismatching assignment and comparison, comparison '' is always false. |
assignmentInCondition | 571 | Suspicious assignment in condition. Condition 'x=y' is always true. |
bitwiseOnBoolean | 398 | Boolean expression 'expression' is used in bitwise operation. Did you mean '&&'? |
catchExceptionByValue | 398 | Exception should be caught by reference. |
clarifyCalculation | 783 | Clarify calculation precedence for '+' and '?'. |
clarifyCondition | 398 | Suspicious condition (assignment + comparison); Clarify expression with parentheses. |
commaSeparatedReturn | 398 | Comma is used in return statement. The comma can easily be misread as a ';'. |
compareValueOutOfTypeRangeError | 398 | Comparing expression of type 'unsigned char' against value 256. Condition is always true. |
comparisonError | 398 | Expression '(X & 0x6) == 0x1' is always false. |
comparisonOfBoolWithBoolError | 398 | Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. |
comparisonOfFuncReturningBoolError | 398 | Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. |
comparisonOfTwoFuncsReturningBoolError | 398 | Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. |
constParameter | — | Parameter 'x' can be declared with const |
constParameterCallback | — | Parameter 'x' can be declared with const, however it seems that 'f' is a callback function. |
constParameterPointer | — | Parameter 'x' can be declared with const |
constParameterReference | — | Parameter 'x' can be declared with const |
constVariable | — | Variable 'x' can be declared with const |
constVariablePointer | — | Variable 'x' can be declared with const |
constVariableReference | — | Variable 'x' can be declared with const |
cstyleCast | 398 | C-style pointer casting |
duplicateAssignExpression | 398 | Same expression used in consecutive assignments of 'x' and 'x'. |
duplicateBranch | 398 | Found duplicate branches for 'if' and 'else'. |
duplicateBreak | 561 | Consecutive return, break, continue, goto or throw statements are unnecessary. |
duplicateCondition | 398 | The if condition is the same as the previous if condition |
duplicateConditionalAssign | 398 | Duplicate expression for the condition and assignment. |
duplicateExpression | 398 | Same expression on both sides of '&&'. |
duplicateExpressionTernary | 398 | Same expression in both branches of ternary operator. |
duplicateValueTernary | 398 | Same value in both branches of ternary operator. |
exceptRethrowCopy | 398 | Throwing a copy of the caught exception instead of rethrowing the original exception. |
funcArgNamesDifferent | 628 | Function 'function' argument 2 names different: declaration '<unnamed>' definition '<unnamed>'. |
functionConst | 398 | Technically the member function 'class::function' can be const. |
functionStatic | 398 | The member function 'class::function' can be static. |
ignoredReturnErrorCode | 252 | Error code from the return value of function func_name() is not used. |
incrementboolean | 398 | Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. |
initializerList | 398 | Member variable 'class::variable' is in the wrong place in the initializer list. |
knownArgument | — | Argument 'x-x' to function 'func' is always 0. It does not matter what value 'x' has. |
knownArgumentHiddenVariableExpression | — | Argument 'x*0' to function 'func' is always 0. Constant literal calculation disable/hide variable expression 'x'. |
knownConditionTrueFalse | 570 | Condition 'x' is always false |
knownEmptyContainer | 398 | Iterating over container 'var' that is always empty. |
knownPointerToBool | — | Pointer expression 'p' converted to bool is always true. |
mismatchingBitAnd | 398 | Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). |
missingOverride | — | The function '' overrides a function in a base class but is not marked with a 'override' specifier. |
moduloofone | — | Modulo of one is always equal to zero |
multiCondition | 398 | Expression is always false because 'else if' condition matches previous condition at line 1. |
nanInArithmeticExpression | 369 | Using NaN/Inf in a computation. |
noConstructor | 398 | The class 'classname' does not declare a constructor although it has private member variables which likely require initialization. |
noExplicitConstructor | 398 | Class 'classname' has a constructor with 1 argument that is not explicit. |
operatorEqRetRefThis | 398 | 'operator=' should return reference to 'this' instance. |
operatorEqShouldBeLeftUnimplemented | 398 | 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. |
oppositeExpression | 398 | Opposite expression on both sides of '&&'. |
pointerLessThanZero | 570 | A pointer can not be negative so it is either pointless or an error to check if it is. |
pointerPositive | 570 | A pointer can not be negative so it is either pointless or an error to check if it is not. |
redundantAssignInSwitch | 563 | Variable 'var' is reassigned a value before the old one has been used. 'break;' missing? |
redundantAssignment | 563 | Variable 'var' is reassigned a value before the old one has been used. |
redundantBitwiseOperationInSwitch | — | Redundant bitwise operation on 'varname' in 'switch' statement. 'break;' missing? |
redundantCondition | 398 | Redundant condition: If x > 11 the condition x > 10 is always true. |
redundantContinue | 561 | 'continue' is redundant since it is the last statement in a loop. |
redundantIfRemove | 398 | Redundant checking of STL container element existence before removing it. |
redundantInitialization | 563 | Redundant initialization for 'var'. The initialized value is overwritten before it is read. |
redundantPointerOp | 398 | Redundant pointer operation on 'varname' - it's already a pointer. |
returnNonBoolInBooleanFunction | — | Non-boolean value returned from function returning bool |
sameIteratorExpression | 664 | Same iterators expression are used for algorithm. |
selfAssignment | 398 | Redundant assignment of 'varname' to itself. |
shadowArgument | 398 | Local variable 'local variable' shadows outer argument |
shadowFunction | 398 | Local variable 'local variable' shadows outer function |
shadowMember | 398 | Local variable 'local variable' shadows outer member |
shadowVariable | 398 | Local variable 'local variable' shadows outer variable |
staticFunction | — | The function 'funcName' should have static linkage since it is not used outside of its translation unit. |
suspiciousFloatingPointCast | 398 | Floating-point cast causes loss of precision. |
truncLongCastAssignment | 197 | int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. |
truncLongCastReturn | 197 | int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. |
unassignedVariable | 665 | Variable 'varname' is not assigned a value. |
unhandledExceptionSpecification | 703 | Unhandled exception specification when calling function foo(). |
unpreciseMathCall | 758 | Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. |
unreachableCode | 561 | Statements following return, break, continue, goto or throw will never be executed. |
unreadVariable | 563 | Variable 'varname' is assigned a value that is never used. |
unsafeClassCanLeak | 398 | Class 'class' is unsafe, 'class::varname' can leak by wrong usage. |
unsignedLessThanZero | 570 | Checking if unsigned expression 'varname' is less than zero. |
unsignedPositive | 570 | Unsigned expression 'varname' can't be negative so it is unnecessary to test it. |
unusedAllocatedMemory | 563 | Variable 'varname' is allocated memory that is never used. |
unusedFunction | 561 | The function 'funcName' is never used. |
unusedLabel | 398 | Label '' is not used. |
unusedLabelConfiguration | 398 | Label '' is not used. There is #if in function body so the label might be used in code that is removed by the preprocessor. |
unusedPrivateFunction | 398 | Unused private function: 'classname::funcname' |
unusedScopedObject | 563 | Instance of 'varname' object is destroyed immediately. |
unusedStructMember | 563 | struct member 'structname::variable' is never used. |
unusedVariable | 563 | Unused variable: varname |
uselessAssignmentArg | 398 | Assignment of function parameter has no effect outside the function. |
uselessOverride | — | The function '' overrides a function in a base class but just delegates back to the base class. |
useStandardLibrary | — | Consider using memcpy instead of loop. |
useStlAlgorithm | 398 | Consider using algorithm instead of a raw loop. |
variableScope | 398 | The scope of the variable 'varname' can be reduced. |
virtualCallInConstructor | — | Virtual function 'f' is called from constructor '' at line 1. Dynamic binding is not used. |
performance(性能)(19 项)
| Error ID | CWE | 说明(cppcheck 原始消息) |
|---|---|---|
passedByValue | 398 | Function parameter '' should be passed by const reference. |
postfixOperator | 398 | Prefer prefix ++/-- operators for non-primitive types. |
redundantCopy | 563 | Buffer 'var' is being written before its old content has been used. |
redundantCopyLocalConst | 398 | Use const reference for 'varname' to avoid unnecessary data copying. |
returnByReference | — | Function 'func()' should return member 'var' by const reference. |
returnStdMoveLocal | — | Using std::move for returning object by-value from function will affect copy elision optimization. More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local |
stlcstrAssignment | 704 | Assigning the result of c_str() to a std::string is slow and redundant. |
stlcstrConcat | 704 | Concatenating the result of c_str() and a std::string is slow and redundant. |
stlcstrConstructor | 704 | Constructing a std::string from the result of c_str() is slow and redundant. |
stlcstrParam | 704 | Passing the result of c_str() to a function that takes std::string as argument no. 0 is slow and redundant. |
stlcstrReturn | 704 | Returning the result of c_str() in a function that returns std::string is slow and redundant. |
stlcstrStream | 704 | Passing the result of c_str() to a stream is slow and redundant. |
stlFindInsert | 398 | Searching before insertion is not necessary. |
stlIfStrFind | 597 | Inefficient usage of string::find() in condition; string::starts_with() could be faster. |
stlSize | 398 | Possible inefficient checking for 'list' emptiness. |
useInitializationList | 398 | Variable 'variable' is assigned in constructor body. Consider performing initialization in initialization list. |
uselessCallsConstructor | 398 | Inefficient constructor call: container '' is assigned a partial copy of itself. Use erase() or resize() instead. |
uselessCallsSubstr | 398 | Ineffective call of function 'substr' because it returns a copy of the object. Use operator= instead. |
uselessCallsSwap | 628 | It is inefficient to swap a object with itself by calling 'str.swap(str)' |
portability(可移植性)(20 项)
| Error ID | CWE | 说明(cppcheck 原始消息) |
|---|---|---|
arithOperationsOnVoidPointer | 467 | 'varname' is of type 'vartype'. When using void pointers in calculations, the behaviour is undefined. |
AssignmentAddressToInteger | 758 | Assigning a pointer to an integer is not portable. |
AssignmentIntegerToAddress | 758 | Assigning an integer to a pointer is not portable. |
CastAddressToIntegerAtReturn | 758 | Returning an address value in a function with integer return type is not portable. |
CastIntegerToAddressAtReturn | 758 | Returning an integer in a function with pointer return type is not portable. |
fflushOnInputStream | 398 | fflush() called on input stream 'stdin' may result in undefined behaviour on non-linux systems. |
intToPointerCast | 398 | Casting non-zero decimal integer literal to pointer. |
invalidConstFunctionType | — | It is unspecified behavior to const qualify a function type. |
invalidPointerCast | 704 | Casting between float * and double * which have an incompatible binary data representation. |
memsetClassFloat | 758 | Using memset() on class which contains a floating point number. |
memsetFloat | 688 | The 2nd memset() argument 'varname' is a float, its representation is implementation defined. |
nonStandardCharLiteral | — | Non-standard character literal. |
pointerOutOfBounds | 758 | Pointer arithmetic overflow. |
pointerOutOfBoundsCond | 758 | Pointer arithmetic overflow. |
shiftNegativeLHS | 758 | Shifting a negative value is technically undefined behaviour |
sizeofDereferencedVoidPointer | 682 | '*varname' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard. |
sizeofVoid | 682 | Behaviour of 'sizeof(void)' is not covered by the ISO C standard. |
UnionZeroInit | — | Zero initializing union '' does not guarantee its complete storage to be zero initialized as its largest member is not declared as the first member. Consider making the first member or favor memset(). |
unknownSignCharArrayIndex | 758 | 'char' type used as array index. |
varFuncNullUB | 475 | Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. |
information(信息)(5 项)
| Error ID | CWE | 说明(cppcheck 原始消息) |
|---|---|---|
class_X_Y | — | The code ' ' is not handled. You can use -I or --include to add handling of this code. |
missingInclude | — | Include file: "" not found. |
missingIncludeSystem | — | Include file: <> not found. Please note: Standard library headers do not need to be provided to get proper results. |
purgedConfiguration | — | The configuration '' was not checked because its code equals another one. |
toomanyconfigs | 398 | Too many #ifdef configurations - cppcheck only checks 12 of 0 configurations. Use --force to check all configurations. |
4 附加能力(MISRA / 规则文件 / 抑制 / CWE)
- 编码规范插件(addon):
--addon=misra校验 MISRA C 2012;另有cert、y2038、threadsafety等 addon。需配--addon=misra.json指定规则文本映射。 - 自定义规则:
--rule="<regex>"或--rule-file=rules.xml可用正则/Token 表达式定义项目专有检查,用于落地几何内核等领域特有的可静态化约束。 - 内联抑制:在代码中写
// cppcheck-suppress <errorId>(上一行或行内),用于已确认的误报;项目级误报集中在suppressions.txt。 - CWE 映射:每个检查项带有
cwe属性,便于与安全合规(如 SEI CERT、CWE Top 25)对接。
5 标准知识条目列表
本节分两层:§5.2 标准条目覆盖全部 342 项代码缺陷检查规则(含规则说明);§5.3 深度解析对高频重点检查补充成因、示例、修复与案例。
5.1 条目字段说明
标准条目(§5.2)字段:规则编号、严重级别、CWE、漏洞描述(规则说明)、日志特征。深度解析(§5.3)在此基础上补充:产生原因、影响范围、典型输入、修复建议、相关案例、关联规则。规则编号采用 cppcheck 原生 error id,检测日志方括号内的 id 可直接定位本条目。
5.2 全部检查项·标准知识条目(342 条)
代码缺陷检查规则的标准知识条目,共 342 项(按严重级别分组;每条含 Error ID、严重级别、CWE、说明与日志特征)。高频重点检查的成因/示例/修复/案例见 §5.3。
error(错误)(93 项)
arrayIndexOutOfBounds — error · CWE-788
- 规则编号:
arrayIndexOutOfBounds - 严重级别:error
- CWE:CWE-788
- 漏洞描述:Array 'arr[16]' accessed at index 16, which is out of bounds.
- 日志特征:检测日志以
[arrayIndexOutOfBounds]标识(<file>:<line>:<col>: error: ... [arrayIndexOutOfBounds])
assignBoolToPointer — error · CWE-587
- 规则编号:
assignBoolToPointer - 严重级别:error
- CWE:CWE-587
- 漏洞描述:Boolean value assigned to pointer.
- 日志特征:检测日志以
[assignBoolToPointer]标识(<file>:<line>:<col>: error: ... [assignBoolToPointer])
autoVariables — error · CWE-562
- 规则编号:
autoVariables - 严重级别:error
- CWE:CWE-562
- 漏洞描述:Dangerous assignment - the function parameter is assigned the address of a local auto-variable. Local auto-variables are reserved from the stack which is freed when the function ends. So the pointer to a local variable is invalid after the function ends.
- 日志特征:检测日志以
[autoVariables]标识(<file>:<line>:<col>: error: ... [autoVariables])
autovarInvalidDeallocation — error · CWE-590
- 规则编号:
autovarInvalidDeallocation - 严重级别:error
- CWE:CWE-590
- 漏洞描述:The deallocation of an auto-variable results in undefined behaviour. You should only free memory that has been allocated dynamically.
- 日志特征:检测日志以
[autovarInvalidDeallocation]标识(<file>:<line>:<col>: error: ... [autovarInvalidDeallocation])
bufferAccessOutOfBounds — error · CWE-788
- 规则编号:
bufferAccessOutOfBounds - 严重级别:error
- CWE:CWE-788
- 漏洞描述:Buffer is accessed out of bounds: buf
- 日志特征:检测日志以
[bufferAccessOutOfBounds]标识(<file>:<line>:<col>: error: ... [bufferAccessOutOfBounds])
comparePointers — error · CWE-758
- 规则编号:
comparePointers - 严重级别:error
- CWE:CWE-758
- 漏洞描述:Comparing pointers that point to different objects
- 日志特征:检测日志以
[comparePointers]标识(<file>:<line>:<col>: error: ... [comparePointers])
containerOutOfBounds — error · CWE-398
- 规则编号:
containerOutOfBounds - 严重级别:error
- CWE:CWE-398
- 漏洞描述:Out of bounds access in expression 'container[x]'
- 日志特征:检测日志以
[containerOutOfBounds]标识(<file>:<line>:<col>: error: ... [containerOutOfBounds])
containerOutOfBoundsIndexExpression — error · CWE-398
- 规则编号:
containerOutOfBoundsIndexExpression - 严重级别:error
- CWE:CWE-398
- 漏洞描述:Out of bounds access of var, index 'var.size()' is out of bounds.
- 日志特征:检测日志以
[containerOutOfBoundsIndexExpression]标识(<file>:<line>:<col>: error: ... [containerOutOfBoundsIndexExpression])
coutCerrMisusage — error · CWE-398
- 规则编号:
coutCerrMisusage - 严重级别:error
- CWE:CWE-398
- 漏洞描述:Invalid usage of output stream: '<< std::cout'.
- 日志特征:检测日志以
[coutCerrMisusage]标识(<file>:<line>:<col>: error: ... [coutCerrMisusage])
danglingLifetime — error · CWE-562
- 规则编号:
danglingLifetime - 严重级别:error
- CWE:CWE-562
- 漏洞描述:Non-local variable 'x' will use object.
- 日志特征:检测日志以
[danglingLifetime]标识(<file>:<line>:<col>: error: ... [danglingLifetime])
danglingReference — error · CWE-562
- 规则编号:
danglingReference - 严重级别:error
- CWE:CWE-562
- 漏洞描述:Non-local reference variable 'x' to local variable 'y'
- 日志特征:检测日志以
[danglingReference]标识(<file>:<line>:<col>: error: ... [danglingReference])
danglingTemporaryLifetime — error · CWE-562
- 规则编号:
danglingTemporaryLifetime - 严重级别:error
- CWE:CWE-562
- 漏洞描述:Using object that is a temporary.
- 日志特征:检测日志以
[danglingTemporaryLifetime]标识(<file>:<line>:<col>: error: ... [danglingTemporaryLifetime])
danglingTempReference — error · CWE-562
- 规则编号:
danglingTempReference - 严重级别:error
- CWE:CWE-562
- 漏洞描述:Using reference to dangling temporary.
- 日志特征:检测日志以
[danglingTempReference]标识(<file>:<line>:<col>: error: ... [danglingTempReference])
deallocret — error · CWE-672
- 规则编号:
deallocret - 严重级别:error
- CWE:CWE-672
- 漏洞描述:Returning/dereferencing 'p' after it is deallocated / released
- 日志特征:检测日志以
[deallocret]标识(<file>:<line>:<col>: error: ... [deallocret])
deallocuse — error · CWE-416
- 规则编号:
deallocuse - 严重级别:error
- CWE:CWE-416
- 漏洞描述:Dereferencing 'varname' after it is deallocated / released
- 日志特征:检测日志以
[deallocuse]标识(<file>:<line>:<col>: error: ... [deallocuse])
doubleFree — error · CWE-415
- 规则编号:
doubleFree - 严重级别:error
- CWE:CWE-415
- 漏洞描述:Memory pointed to by 'varname' is freed twice.
- 日志特征:检测日志以
[doubleFree]标识(<file>:<line>:<col>: error: ... [doubleFree])
eraseDereference — error · CWE-664
- 规则编号:
eraseDereference - 严重级别:error
- CWE:CWE-664
- 漏洞描述:The iterator 'iter' is invalid before being assigned. Dereferencing or comparing it with another iterator is invalid operation.
- 日志特征:检测日志以
[eraseDereference]标识(<file>:<line>:<col>: error: ... [eraseDereference])
eraseIteratorOutOfBounds — error · CWE-628
- 规则编号:
eraseIteratorOutOfBounds - 严重级别:error
- CWE:CWE-628
- 漏洞描述:Calling function 'erase()' on the iterator 'iter' which is out of bounds.
- 日志特征:检测日志以
[eraseIteratorOutOfBounds]标识(<file>:<line>:<col>: error: ... [eraseIteratorOutOfBounds])
floatConversionOverflow — error · CWE-190
- 规则编号:
floatConversionOverflow - 严重级别:error
- CWE:CWE-190
- 漏洞描述:Undefined behaviour: float (1e+100) to integer conversion overflow.
- 日志特征:检测日志以
[floatConversionOverflow]标识(<file>:<line>:<col>: error: ... [floatConversionOverflow])
includeNestedTooDeeply — error
- 规则编号:
includeNestedTooDeeply - 严重级别:error
- CWE:—
- 漏洞描述:message
- 日志特征:检测日志以
[includeNestedTooDeeply]标识(<file>:<line>:<col>: error: ... [includeNestedTooDeeply])
integerOverflow — error · CWE-190
- 规则编号:
integerOverflow - 严重级别:error
- CWE:CWE-190
- 漏洞描述:Signed integer overflow for expression ''.
- 日志特征:检测日志以
[integerOverflow]标识(<file>:<line>:<col>: error: ... [integerOverflow])
invalidContainer — error · CWE-664
- 规则编号:
invalidContainer - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Using object that may be invalid.
- 日志特征:检测日志以
[invalidContainer]标识(<file>:<line>:<col>: error: ... [invalidContainer])
invalidContainerLoop — error · CWE-664
- 规则编号:
invalidContainerLoop - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Calling 'erase' while iterating the container is invalid.
- 日志特征:检测日志以
[invalidContainerLoop]标识(<file>:<line>:<col>: error: ... [invalidContainerLoop])
invalidContainerReference — error · CWE-664
- 规则编号:
invalidContainerReference - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Reference to x that may be invalid.
- 日志特征:检测日志以
[invalidContainerReference]标识(<file>:<line>:<col>: error: ... [invalidContainerReference])
invalidFree — error
- 规则编号:
invalidFree - 严重级别:error
- CWE:—
- 漏洞描述:Mismatching address is freed. The address you get from malloc() must be freed without offset.
- 日志特征:检测日志以
[invalidFree]标识(<file>:<line>:<col>: error: ... [invalidFree])
invalidFunctionArg — error · CWE-628
- 规则编号:
invalidFunctionArg - 严重级别:error
- CWE:CWE-628
- 漏洞描述:Invalid func_name() argument nr 1. The value is 0 or 1 (boolean) but the valid values are '1:4'.
- 日志特征:检测日志以
[invalidFunctionArg]标识(<file>:<line>:<col>: error: ... [invalidFunctionArg])
invalidFunctionArgBool — error · CWE-628
- 规则编号:
invalidFunctionArgBool - 严重级别:error
- CWE:CWE-628
- 漏洞描述:Invalid func_name() argument nr 1. A non-boolean value is required.
- 日志特征:检测日志以
[invalidFunctionArgBool]标识(<file>:<line>:<col>: error: ... [invalidFunctionArgBool])
invalidFunctionArgStr — error · CWE-628
- 规则编号:
invalidFunctionArgStr - 严重级别:error
- CWE:CWE-628
- 漏洞描述:Invalid func_name() argument nr 1. A nul-terminated string is required.
- 日志特征:检测日志以
[invalidFunctionArgStr]标识(<file>:<line>:<col>: error: ... [invalidFunctionArgStr])
invalidIterator1 — error · CWE-664
- 规则编号:
invalidIterator1 - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Invalid iterator: iterator
- 日志特征:检测日志以
[invalidIterator1]标识(<file>:<line>:<col>: error: ... [invalidIterator1])
invalidLifetime — error · CWE-562
- 规则编号:
invalidLifetime - 严重级别:error
- CWE:CWE-562
- 漏洞描述:Using object that is out of scope.
- 日志特征:检测日志以
[invalidLifetime]标识(<file>:<line>:<col>: error: ... [invalidLifetime])
invalidScanfFormatWidth — error · CWE-687
- 规则编号:
invalidScanfFormatWidth - 严重级别:error
- CWE:CWE-687
- 漏洞描述:Width 5 given in format string (no. 10) is larger than destination buffer '[0]', use %-1s to prevent overflowing it.
- 日志特征:检测日志以
[invalidScanfFormatWidth]标识(<file>:<line>:<col>: error: ... [invalidScanfFormatWidth])
invalidSuppression — error
- 规则编号:
invalidSuppression - 严重级别:error
- CWE:—
- 漏洞描述:message
- 日志特征:检测日志以
[invalidSuppression]标识(<file>:<line>:<col>: error: ... [invalidSuppression])
IOWithoutPositioning — error · CWE-664
- 规则编号:
IOWithoutPositioning - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour.
- 日志特征:检测日志以
[IOWithoutPositioning]标识(<file>:<line>:<col>: error: ... [IOWithoutPositioning])
iterators1 — error · CWE-664
- 规则编号:
iterators1 - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Same iterator is used with different containers 'container1' and 'container2'.
- 日志特征:检测日志以
[iterators1]标识(<file>:<line>:<col>: error: ... [iterators1])
iterators3 — error · CWE-664
- 规则编号:
iterators3 - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Same iterator is used with containers 'container' that are temporaries or defined in different scopes.
- 日志特征:检测日志以
[iterators3]标识(<file>:<line>:<col>: error: ... [iterators3])
leakNoVarFunctionCall — error · CWE-772
- 规则编号:
leakNoVarFunctionCall - 严重级别:error
- CWE:CWE-772
- 漏洞描述:Allocation with funcName, funcName doesn't release it.
- 日志特征:检测日志以
[leakNoVarFunctionCall]标识(<file>:<line>:<col>: error: ... [leakNoVarFunctionCall])
leakReturnValNotUsed — error · CWE-771
- 规则编号:
leakReturnValNotUsed - 严重级别:error
- CWE:CWE-771
- 漏洞描述:Return value of allocation function 'funcName' is not stored.
- 日志特征:检测日志以
[leakReturnValNotUsed]标识(<file>:<line>:<col>: error: ... [leakReturnValNotUsed])
mallocOnClassError — error · CWE-665
- 规则编号:
mallocOnClassError - 严重级别:error
- CWE:CWE-665
- 漏洞描述:Memory for class instance allocated with malloc(), but class a std::string. This is unsafe, since no constructor is called and class members remain uninitialized. Consider using 'new' instead.
- 日志特征:检测日志以
[mallocOnClassError]标识(<file>:<line>:<col>: error: ... [mallocOnClassError])
memleak — error · CWE-401
- 规则编号:
memleak - 严重级别:error
- CWE:CWE-401
- 漏洞描述:Memory leak: varname
- 日志特征:检测日志以
[memleak]标识(<file>:<line>:<col>: error: ... [memleak])
memleakOnRealloc — error · CWE-401
- 规则编号:
memleakOnRealloc - 严重级别:error
- CWE:CWE-401
- 漏洞描述:Common realloc mistake: 'varname' nulled but not freed upon failure
- 日志特征:检测日志以
[memleakOnRealloc]标识(<file>:<line>:<col>: error: ... [memleakOnRealloc])
memsetClass — error · CWE-762
- 规则编号:
memsetClass - 严重级别:error
- CWE:CWE-762
- 漏洞描述:Using 'memfunc' on class that contains a classname is unsafe, because constructor, destructor and copy operator calls are omitted. These are necessary for this non-POD type to ensure that a valid object is created.
- 日志特征:检测日志以
[memsetClass]标识(<file>:<line>:<col>: error: ... [memsetClass])
memsetClassReference — error · CWE-665
- 规则编号:
memsetClassReference - 严重级别:error
- CWE:CWE-665
- 漏洞描述:Using 'memfunc' on class that contains a reference.
- 日志特征:检测日志以
[memsetClassReference]标识(<file>:<line>:<col>: error: ... [memsetClassReference])
mismatchAllocDealloc — error · CWE-762
- 规则编号:
mismatchAllocDealloc - 严重级别:error
- CWE:CWE-762
- 漏洞描述:Mismatching allocation and deallocation: varname
- 日志特征:检测日志以
[mismatchAllocDealloc]标识(<file>:<line>:<col>: error: ... [mismatchAllocDealloc])
mismatchingContainerIterator — error · CWE-664
- 规则编号:
mismatchingContainerIterator - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Iterator 'it' referring to container 'v2' is used with container 'v1'.
- 日志特征:检测日志以
[mismatchingContainerIterator]标识(<file>:<line>:<col>: error: ... [mismatchingContainerIterator])
mismatchingContainers — error · CWE-664
- 规则编号:
mismatchingContainers - 严重级别:error
- CWE:CWE-664
- 漏洞描述:Iterators of different containers 'v1' and 'v2' are used together.
- 日志特征:检测日志以
[mismatchingContainers]标识(<file>:<line>:<col>: error: ... [mismatchingContainers])
missingFile — error
- 规则编号:
missingFile - 严重级别:error
- CWE:—
- 漏洞描述:message
- 日志特征:检测日志以
[missingFile]标识(<file>:<line>:<col>: error: ... [missingFile])
missingIncludeExplicit — error
- 规则编号:
missingIncludeExplicit - 严重级别:error
- CWE:—
- 漏洞描述:message
- 日志特征:检测日志以
[missingIncludeExplicit]标识(<file>:<line>:<col>: error: ... [missingIncludeExplicit])
missingReturn — error · CWE-758
- 规则编号:
missingReturn - 严重级别:error
- CWE:CWE-758
- 漏洞描述:Found an exit path from function with non-void return type that has missing return statement
- 日志特征:检测日志以
[missingReturn]标识(<file>:<line>:<col>: error: ... [missingReturn])
negativeArraySize — error · CWE-758
- 规则编号:
negativeArraySize - 严重级别:error
- CWE:CWE-758
- 漏洞描述:Declaration of array '' with negative size is undefined behaviour
- 日志特征:检测日志以
[negativeArraySize]标识(<file>:<line>:<col>: error: ... [negativeArraySize])
negativeIndex — error · CWE-786
- 规则编号:
negativeIndex - 严重级别:error
- CWE:CWE-786
- 漏洞描述:Negative array index
- 日志特征:检测日志以
[negativeIndex]标识(<file>:<line>:<col>: error: ... [negativeIndex])
negativeMemoryAllocationSize — error · CWE-131
- 规则编号:
negativeMemoryAllocationSize - 严重级别:error
- CWE:CWE-131
- 漏洞描述:Memory allocation size is negative.
- 日志 特征:检测日志以
[negativeMemoryAllocationSize]标识(<file>:<line>:<col>: error: ... [negativeMemoryAllocationSize])
nullPointer — error · CWE-476
- 规则编号:
nullPointer - 严重级别:error
- CWE:CWE-476
- 漏洞描述:Null pointer dereference
- 日志特征:检测日志以
[nullPointer]标识(<file>:<line>:<col>: error: ... [nullPointer])
nullPointerArithmetic — error · CWE-682
- 规则编号:
nullPointerArithmetic - 严重级别:error
- CWE:CWE-682
- 漏洞描述:Pointer arithmetic with NULL pointer.
- 日志特征:检测日志以
[nullPointerArithmetic]标识(<file>:<line>:<col>: error: ... [nullPointerArithmetic])
objectIndex — error · CWE-758
- 规则编号:
objectIndex - 严重级别:error
- CWE:CWE-758
- 漏洞描述:The address of variable '' is accessed at non-zero index.
- 日志特征:检测日志以
[objectIndex]标识(<file>:<line>:<col>: error: ... [objectIndex])
operatorEqMissingReturnStatement — error · CWE-398
- 规则编号:
operatorEqMissingReturnStatement - 严重级别:error
- CWE:CWE-398
- 漏洞描述:No 'return' statement in non-void function causes undefined behavior.
- 日志特征:检测日志以
[operatorEqMissingReturnStatement]标识(<file>:<line>:<col>: error: ... [operatorEqMissingReturnStatement])
overlappingWriteFunction — error
- 规则编号:
overlappingWriteFunction - 严重级别:error
- CWE:—
- 漏洞描述:Overlapping read/write in funcname() is undefined behavior
- 日志特征:检测日志以
[overlappingWriteFunction]标识(<file>:<line>:<col>: error: ... [overlappingWriteFunction])
overlappingWriteUnion — error
- 规则编号:
overlappingWriteUnion - 严重级别:error
- CWE:—
- 漏洞描述:Overlapping read/write of union is undefined behavior
- 日志特征:检测日志以
[overlappingWriteUnion]标识(<file>:<line>:<col>: error: ... [overlappingWriteUnion])
pointerArithBool — error · CWE-571
- 规则编号:
pointerArithBool - 严重级别:error
- CWE:CWE-571
- 漏洞描述:Converting pointer arithmetic result to bool. The boolean result is always true unless there is pointer arithmetic overflow, and overflow is undefined behaviour. Probably a dereference is forgotten.
- 日志特征:检测日志以
[pointerArithBool]标识(<file>:<line>:<col>: error: ... [pointerArithBool])
preprocessorErrorDirective — error
- 规则编号:
preprocessorErrorDirective - 严重级别:error
- CWE:—
- 漏洞描述:message
- 日志特征:检测日志以
[preprocessorErrorDirective]标识(<file>:<line>:<col>: error: ... [preprocessorErrorDirective])
raceAfterInterlockedDecrement — error · CWE-362
- 规则编号:
raceAfterInterlockedDecrement - 严重级别:error
- CWE:CWE-362