question about Conditional jump or move depends on uninitialised value

my program fails when I am running on the linux machine with c++98. anything will be appreciated.

==22511== Command: ./wordcount --track-origins=yes
==22511==
==22511== Conditional jump or move depends on uninitialised value(s)
==22511== at 0x401316: BHeap<std::string>::sort() (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511== by 0x40103E: main (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511==
==22511== Conditional jump or move depends on uninitialised value(s)
==22511== at 0x4016CF: BHeap<std::string>::pop() (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511== by 0x401300: BHeap<std::string>::sort() (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511== by 0x40103E: main (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511==
==22511== Conditional jump or move depends on uninitialised value(s)
==22511== at 0x4018ED: std::vector<std::string*, std::allocator<std::string*> >::_M_range_check(unsigned long) const (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511== by 0x40146E: std::vector<std::string*, std::allocator<std::string*> >::at(unsigned long) (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511== by 0x401D52: BHeap<std::string>::swap(int, int) (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511== by 0x401702: BHeap<std::string>::pop() (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511== by 0x401300: BHeap<std::string>::sort() (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511== by 0x40103E: main (in /net/metis/home/dhk5/502/lab3/wordcount)
==22511==
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class BHeap  {

public:
BHeap() : end_point(0) {}
private:
int end_point;

vector<string*> sorted_list = heap.sort();
   for(int i = 0; i < sorted_list.size(); ++i) {
      string* temp = sorted_list.at(i);
      cout << *temp << endl;

template<typename T>
std::vector<T*> BHeap<T>::sort()  {
   while (!is_empty()) {
      T* temp = pop();
      (void)temp;
   }
   std::reverse(heap_list.begin(), heap_list.end());
   return heap_list;
}

template<typename T>
T* BHeap<T>::pop()  {
   T* temp_return = NULL;
   if (!is_empty())  {
      temp_return = heap_list.front();
      swap(0, (int)end_point - 1);
      end_point--;
      down_heap(0, end_point);
   }
   return temp_return;
}

template<typename T>
void BHeap<T>::swap(int data1, int data2)  {
   T* temp = NULL;
   temp = heap_list.at(data1);
   heap_list.at(data1) = heap_list.at(data2);
   heap_list.at(data2) = temp;
}
Last edited on
You should type --track-origins=yes before the name of your program otherwise it is your program that receives it instead of valgrind.
Topic archived. No new replies allowed.