在压入vector时读取大小为4的数据无效
Invalid read of size 4 during pushing to vector
你好,我有一个错误从valgrind:
==19383== Invalid read of size 4
==19383== at 0x57F69FB: xy(int, int) (Generator.cpp:228)
==19383== by 0x57F71E2: getNext() (Generator.cpp:164)
. . .
. . .
==19383== Address 0x90ddbec is 4 bytes before a block of size 4 alloc'd
==19383== at 0x4C28C20: malloc (vg_replace_malloc.c:296)
==19383== by 0x57FE9B7: operator new(unsigned long) (in /xx.so)
==19383== by 0x57F79BA: allocate (new_allocator.h:104)
==19383== by 0x57F79BA: allocate (alloc_traits.h:357)
==19383== by 0x57F79BA: _M_allocate (stl_vector.h:170)
==19383== by 0x57F79BA: void std::vector<int, std::allocator<int> >::_M_emplace_back_aux<int const&>(int const&) (vector.tcc:412)
==19383== by 0x57F6F49: push_back (stl_vector.h:923)
==19383== by 0x57F6F49: reset() (Generator.cpp:142)
. . .
. . .
==19383== by 0x40A8FC: main (main.cpp:24)
==19383==
==19383==
==19383== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ----
和reset()函数看起来像:
void reset()
{
this->first = true;
std::vector<int>* counts = this->counts_iterator.getNext();
(*this->picks).clear();
for(unsigned int i = 0; i < this->variant->groups.size(); i++)
{
(*this->picks).push_back(std::vector<int> ());
for(int j = 0; j < (*counts)[i]; j++)
{
(*this->picks)[i].push_back(j);
}
}
}
在调用函数reset()之前:
this->picks = new std::vector<std::vector<int> > ();
有变量定义:
std::vector<std::vector<int> >* picks;
我不知道为什么我得到这个错误。什么好主意吗?由于
正如@ecatmur所说的问题在其他地方,在文件sy .cpp中,正如valgrind所说的…
相关文章:
- 如何在c++中定义以struct为数据成员的类中的构造函数
- 我们可以将数据永久保存为数据结构吗?
- 我的头文件 DNode 中的我的数据类型未被识别为数据类型
- 如何将PyObjects转换为C数据类型
- 如何在Qt TableView中将列的宽度调整为数据并将最后一部分拉伸在一起
- 标记为 [数据成员] 时的意外类型'USN'
- 数据对齐:限制内存地址为数据类型大小倍数的原因
- 如何为数据类型 vector<glm::vec3> (opengl 数据类型) 编写 std::minmax 函数的自定义比较器
- 为数据缺少默认构造函数的链表创建节点
- 显示为数据类型的纯虚拟类
- 将 json 解析为数据模型 [是:C++头文件设计]
- 是否值得两次通过文件进行迭代,以创建最小的数据结构
- 搜索一组点,其长度总和最小为矩形.算法是什么
- 如何在c++中为数据中的特定数字分配字母
- C++为数据记录定义宏
- 将对象强制转换为数据类型
- 在C++中根据需要为数据结构分配空间
- 数组是否为数据类型
- C++ - 将 int 拆分为两种较小的数据类型
- 从较大的数据类型(结构)转换为较小的数据类型