☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

空指针解引用

C++-Undefined-Behavior-55
目录 › next › previous

空指针未指向任何对象或函数,解引用空指针会导致未定义的行为。

示例:

int* a = nullptr;
*a = 1;            // Undefined behavior
a[5] = 2;          // Undefined behavior
memset(a, 0, 10);  // Undefined behavior

struct T {
    int i;
    int f();
};
T* p = nullptr;
p->i = 0;          // Undefined behavior
p->f();            // Undefined behavior

using F = void (*)();
F fp = nullptr;
fp();              // Undefined behavior

依据

ISO/IEC 14882:2003 8.3.2(4)-undefined ISO/IEC 14882:2011 8.3.2(5)-undefined

规则

ID_nullDerefInScp ID_nullDerefInExp
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.