CodeQL 文档

由于先前的解引用导致的冗余空检查

ID: cpp/redundant-null-check-simple
Kind: path-problem
Security severity: 7.5
Severity: error
Precision: high
Tags:
   - reliability
   - correctness
   - security
   - external/cwe/cwe-476
Query suites:
   - cpp-code-scanning.qls
   - cpp-security-extended.qls
   - cpp-security-and-quality.qls

点击查看 CodeQL 代码库中的查询

此规则查找在对指针进行引用后发生的指针与空的比较。很可能不需要进行检查并且可以将其删除,或者应该在解引用之前将其移动,以便不会发生空指针解引用。

建议

应在解引用之前将检查移动到可以防止解引用空指针值的位置。如果很明显指针不能为空,请考虑改为删除检查。

示例

int f(MyList *list) {
	list->append(1);

	// ...

	if (list != NULL)
	{
		list->append(2);
	}
}

参考

  • ©GitHub 公司
  • 条款
  • 隐私