我一直在寻找这个错误,但似乎无法找到它。
Valgrind 告诉我:
Uninitialised value was created by a heap allocation
==31732== at 0x4C28B35: operator new(unsigned long) (vg_replace_malloc.c:261)
==31732== by 0x406B87: __gnu_cxx::new_allocator<int>::allocate(unsigned long void const*) (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
==31732== by 0x40560C: std::_Vector_base<int, std::allocator<int> >::_M_allocate(unsigned long) (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
==31732== by 0x40497A: std::vector<int, std::allocator<int> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, int const&) (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
==31732== by 0x403B15: std::vector<int, std::allocator<int> >::push_back(int const&) (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
==31732== by 0x413655: Compressor::getMTF(std::string const&) (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
==31732== by 0x412EE4: Compressor::compress(std::string&) (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
==31732== by 0x40E2FB: Opp::Opp(std::string&) (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
==31732== by 0x402098: FMindex::FMindex(std::string&) (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
==31732== by 0x41DE0B: main (in /home/matija/Documents/FER/6.semestar/dna-assembly/FMindex/src/test)
对于这段代码。据我从这条消息中可以看出,推送到向量时似乎有一个错误,但我就是不明白。我还收到一个“条件跳转或移动取决于未初始化的值”错误,我想这是这个错误的结果。我错过了什么吗?
vector<int> Compressor::getMTF(const string& L)
{
// Construct initial MTF list
list<char> MTFList = alphabet.toSortedList();
// Generate MTF code for L
vector<int> MTF;
for (int i = 0; i < L.length(); i++)
{
// If I am at the beginning of a bucket, store current MTF state
if (i % bucketSize == 0)
{
MTFStates.push_back(MTFList);
}
// Find position of L[i] in MTFList and encode it
list<char>::iterator it;
int pos = 0;
for (pos = 0, it = MTFList.begin(); it != MTFList.end(); it++, pos++)
if (*it == L[i])
{
MTF.push_back(pos);
MTFList.push_front(*it);
MTFList.erase(it);
break;
}
}
return MTF;
}