C++ valgrind中大小为8的读取无效
Valgrind显示以下错误消息C++ valgrind中大小为8的读取无效,c++,valgrind,C++,Valgrind,Valgrind显示以下错误消息 ==8584== Invalid read of size 8 ==8584== at0x4CA885D:VPR::VidSegment::getMCmean(std::vector<std::vector<CvRect, std::allocator<CvRect> >, std::allocator<std::vector<CvRect, std::allocator<CvRect> > >
==8584== Invalid read of size 8
==8584== at0x4CA885D:VPR::VidSegment::getMCmean(std::vector<std::vector<CvRect, std::allocator<CvRect> >, std::allocator<std::vector<CvRect, std::allocator<CvRect> > > > const&) const (VidSegment.cpp:678)
==8584== by 0x4CAE071: VPR::VidSegment::getSegments(std::vector<CvRect, std::allocator<CvRect> >, _IplImage const*) (VidSegment.cpp:234)
vector<CvRect> VidSegment::getMCmean(const vector< vector<CvRect> >& majorCluster) const
{
vector<CvRect> meanvaluesN;
for (int i = 0; i < (int) majorCluster.size(); i++ )
{
int sumH=0, sumY=0, sumW=0, sumB=0;
vector<CvRect> tempV = majorCluster[i];
//Here-------------->
for (int j = 0; j < (int) tempV.size(); j++)
{
sumH += tempV[j].height;
sumW += tempV[j].width;
sumY += tempV[j].y;
sumB += (tempV[j].y + tempV[j].height);
}
sumH /= tempV.size();
sumY /= tempV.size();
sumW /= tempV.size();
sumB /= tempV.size();
meanvaluesN.push_back(cvRect(sumH, sumY, sumW, sumB));
}
return meanvaluesN;
}
==8584==大小为8的无效读取
==8584==at0x4CA885D:VPR::VidSegment::getMCmean(std::vector const&)const(VidSegment.cpp:678)
==8584==by 0x4CAE071:VPR::VidSegment::getSegments(std::vector,_iplimageconst*)(VidSegment.cpp:234)
vector VidSegment::getMCmean(常量向量&majorCluster)常量
{
向量均值n;
对于(int i=0;i<(int)majorCluster.size();i++)
{
int sumH=0,sumY=0,sumW=0,sumB=0;
向量tempV=大星系团[i];
//这里----------------->
对于(int j=0;j<(int)tempV.size();j++)
{
sumH+=tempV[j]。高度;
sumW+=tempV[j]。宽度;
sumY+=tempV[j].y;
sumB+=(tempV[j].y+tempV[j].高度);
}
sumH/=tempV.size();
sumY/=tempV.size();
sumW/=tempV.size();
sumB/=tempV.size();
平均值推后(cvRect(sumH、sumY、sumW、sumB));
}
返回平均值n;
}
我找不到它为什么显示上述消息
有人能说出原因吗
我也收到了下面的错误信息
==8584== Address 0x960107c is 252 bytes inside a block of size 256 alloc'd
==8584== at 0x4A075BC: operator new(unsigned long) (vg_replace_malloc.c:298)
==8584== by 0x4CA87A4: VPR::VidSegment::getMCmean(std::vector<std::vector<CvRect, std::allocator<CvRect> >, std::allocator<std::vector<CvRect, std::allocator<CvRect> > > > const&) const (new_allocator.h:89)
==8584==地址0x960107c是大小为256 alloc的块中的252字节
==8584==0x4A075BC处:运算符新(无符号长)(vg_替换_malloc.c:298)
==8584==by 0x4CA87A4:VPR::VidSegment::getMCmean(std::vector const&)const(new_allocator.h:89)
在我所写的代码中,哪一行是678和234?678,这里是----------------->省去了一个明显的问题,一些反对迭代器的东西?只是好奇。请澄清在最近释放的内存中,无效读取发生的位置-通常位于分配块之前或之后。它显示在VidSegment.cpp+678,对应于上述代码中的行//此处----------------->