为什么 CppCheck 会为此静态 const 数组提供越界访问错误
Why does CppCheck give an array access out of bounds error for this static const array?
CppCheck 1.67 已识别并在我的一个项目上越界访问数组错误。我不认为代码是错误的,所以我将代码精简到仍然引发相同错误的最小示例。为什么 CppCheck 对第一个C++示例(在命名空间内)给出以下错误,而对第二个示例(没有命名空间)没有给出以下错误?
我在数组初始化时对命名空间做了什么错误,还是这是 CppCheck 中的错误?
报告错误:"数组'testArray[5]'在索引 5 处访问,这超出了界限。
namespace TestNamespace
{
class TestClass
{
static const int testArray[5];
};
const int TestClass::testArray[] = { 1, 2, 3, 4, 5};
}
未报告错误:
class TestClass
{
static const int testArray[5];
};
const int TestClass::testArray[] = { 1, 2, 3, 4, 5};
似乎是
CppCheck 中的一个错误,可能与跟踪器上的此问题有关:
FP arrayIndexOutOfBounds:在命名空间中声明的类的成员变量。
相关文章:
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 用于访问容器<T>数据成员的正确 API
- 访问者访问变体并返回不同类型时出错
- 尝试通过多个向量访问变量时,向量下标超出范围
- 无法访问嵌套类.类的使用无效
- 写入位置0x0000000C时发生访问冲突
- 我们可以访问一个不存在的联盟的成员吗
- C++从另一个类访问公共静态向量的正确方法是什么
- 我的简单if-else语句是如何无法访问的代码
- 从C++dll访问C#中的一行主要参数
- 越界访问 CUDA 共享内存
- 访问矢量元素时索引越界异常
- 为什么这种越界访问没有段错误?
- 为什么编译器允许越界数组访问,即使使用 constexpr 索引也是如此
- 为什么 CppCheck 会为此静态 const 数组提供越界访问错误
- 在 iPhone 上追踪越界访问
- 检查可能的访问/创建越界指针
- 为什么当我访问数组的越界元素时没有收到运行时错误?