您好,我有来自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;
我不确定为什么会收到此错误。有任何想法吗? 感谢
答案 0 :(得分:0)
正如@ecatmur所说的问题是在其他地方,在文件xy.cpp中,因为valgrind说...