ES.65: Don't dereference an invalid pointer
ES.65:不要解引用无效指针
Reason(原因)
Dereferencing an invalid pointer, such as nullptr, is undefined behavior, typically leading to immediate crashes, wrong results, or memory corruption.
解引用例如null等无效指针,是无定义的行为,通常会立即导致程序崩溃,错误的结果,或者内存破坏。
Note(注意)
This rule is an obvious and well-known language rule, but can be hard to follow. It takes good coding style, library support, and static analysis to eliminate violations without major overhead. This is a major part of the discussion of C++'s model for type- and resource-safety.
本规则显而易见而且众所周知,但却很难遵守。它会带来好的代码风格,更充分的库支持,不需要很大代价但可以排除违反的静态解析。这是关于C++类型和资源安全模型的论述的重要组成部分。
See also:(参见)
- Use RAII to avoid lifetime problems.
- 使用RAII避免生命周期问题。
- Use unique_ptr to avoid lifetime problems.
- 使用uniq