Ошибка сегментации (ошибка сброса ядра) при вызове функции

#segmentation-fault

Вопрос:

Я получаю ошибку сброса ядра в вызове функции, которая должна возвращать an. Функция передает векторный элемент, который является указателем на структуру, в качестве параметра функции, но взамен приводит к сбросу ядра.

 struct block {  int64_t tag;  bool valid_bit;  bool dirty_bit;  block* next;  block* prev; };  vectorlt; block* gt; cash_set;  

….

 int main (int argc, const char *argv[]) {  int findcash;  ..... if (cash_type == 1)  {  coutlt;lt;"n Fully Associative";  number_of_blocks = cash_size / block_size;   coutlt;lt;"n Enter the Replacement Policy n 0 for Randomn 1 for LRUn 2 for Pseudo LRUn";  cingt;gt;Replacement_policy; // initializing the cache to valid bit as 0 and dirty bit as 0  int i;  cash_set.push_back(NULL);  //Reading file "traces.txt"  associativity=number_of_blocks;   int loc;  newfile.open ("traces.txt", ios::in);   //open a file to perform read operation using file object  if (newfile.is_open ())  { //checking whether the file is open  int count = 0;  while (getline (newfile, tp))  {  cash_access  ;  iss.str (tp);  //read data from file object and put it into string.  cout lt;lt; "n" lt;lt; count   lt;lt; " " lt;lt; tp lt;lt; "n";     //print the data of the string    iss gt;gt; std::hex gt;gt; addr;  cout lt;lt; " Address:" lt;lt; addr lt;lt; "t";  operation = tp.substr (11, 1);  cout lt;lt; operation lt;lt; "n";  //extracting Tag, Index from the address  shift = log2 (block_size);  index_addr = (addr gt;gt; shift) % number_of_blocks;  coutlt;lt;"donen";  shift = log2 (number_of_blocks   block_size);  tag_addr = addr gt;gt; shift;  findcash=find(cash_set[0],tag_addr); //after the above line of code it gives Core dump     coutlt;lt;"nfindcache:"lt;lt;findcash;   

Функция поиска выглядит следующим образом —

 int find(block* tmp,int64_t tag1) {  **if(tmp==NULL)  {  compulsry_misses  ;  coutlt;lt;"Cumpolsary miss:"lt;lt;compulsry_misses;  return 0;  }**  else  {  block* cashblock=tmp;  while(tmp-gt;prev!=NULL)  { // Cache Hit. Bring the accessed node to the front of the DLL   if (tmp-gt;tag==tag1)  {  coutlt;lt;"n Cache Hit"lt;lt;cash_hit;  (tmp-gt;next)-gt;prev=tmp-gt;prev;  (tmp-gt;prev)-gt;next=tmp-gt;next;  cashblock-gt;next=tmp;  tmp-gt;prev=cashblock;  tmp-gt;next=NULL;  cashblock-gt;next=tmp;  cashblock=tmp;  return 1;  }  tmp=tmp-gt;prev;  }  return 0;  }  }  

Traces.txt file contains data as follows —

 0x6b8b4567 w 0x327b23c6 r 0x643c9869 w 0x66334873 r 0x74b0dc51 w 0x19495cff r 0x2ae8944a w ......  

The output after running the code on Ubuntu is as follows —

 ....  Fully Associative  Enter the Replacement Policy   0 for Random  1 for LRU  2 for Pseudo LRU  0    0 0x6b8b4567 w  Address:1804289383 w  done  Cumpolsary miss:1  Segmentation fault (core dumped)