Ticket #60: existingDetections.cc.patch

File existingDetections.cc.patch, 2.8 KB (added by MatthewWhiting, 15 years ago)

New version of the patch file solving segfault issue in existingDetections

  • src/Cubes/existingDetections.cc

     
    5353      return FAILURE;
    5454    }
    5555
    56     std::cout << "Reading from logfile : " << this->par.getLogFile() << "\n";
     56    std::cout << "  Reading from logfile : " << this->par.getLogFile() << "\n";
    5757
    5858    std::string temp,filename;
    5959    std::stringstream ss;
    6060
    6161    // first check filename, just to be sure
    62     while(getline(logfile,temp), temp.substr(0,11)!="Image to be"){}
     62    while(getline(logfile,temp), (temp.size()<11 || temp.substr(0,11)!="Image to be")){}
    6363    ss.str(temp);
    6464    ss >> temp >> temp >> temp >> temp>> temp >> filename;
    6565    if(filename != this->par.getFullImageFile()){
     
    7171    }
    7272
    7373    // read down until first Detection # line
    74     while(getline(logfile,temp), temp.substr(0,9)!="Threshold"){}
     74    while(getline(logfile,temp), (temp.size()<9 || temp.substr(0,9)!="Threshold")){
     75    }
    7576    float threshold,middle,spread;
    7677    bool robust;
    77     logfile >> threshold >> middle >> spread >> robust;
    78     std::cout << "Detection threshold used was " << threshold << "\n";
     78    getline(logfile,temp);
     79    std::stringstream dataline;
     80    dataline.str(temp);
     81    dataline >> threshold >> middle >> spread >> robust;
     82    std::cout << "  Detection threshold used was " << threshold << "\n";
    7983    this->Stats.setRobust(robust);
    8084    this->Stats.setThreshold(threshold);
    8185    this->Stats.setMiddle(middle);
     
    8690    while(!logfile.eof()){
    8791      Detection obj;
    8892      while(getline(logfile,temp), temp.substr(0,3)!="---"){
    89         for(uint i=0;i<temp.size();i++)
    90           if(temp[i]=='-' || temp[i]==',') temp[i] = ' ';
    91         std::stringstream ss;
    92         ss.str(temp);
    93         ss >> x1 >> x2 >> ypix >> zpix;
    94         Scan scn(ypix,x1,x2-x1+1);
    95         obj.pixels().addScan(scn,zpix);
     93        if(temp.substr(0,9)!="Detection"){
     94          for(uint i=0;i<temp.size();i++)
     95            if(temp[i]=='-' || temp[i]==',') temp[i] = ' ';
     96          std::stringstream ss;
     97          ss.str(temp);
     98          ss >> x1 >> x2 >> ypix >> zpix;
     99          Scan scn(ypix,x1,x2-x1+1);
     100          obj.pixels().addScan(scn,zpix);
     101        }
    96102      }
    97103      obj.setOffsets(this->par);
    98       obj.calcParams();
    99       if(obj.getSize()>0) this->addObject(obj);
     104      if(obj.getSize()>0){
     105        obj.calcParams();
     106        this->addObject(obj);
     107      }
    100108      getline(logfile,temp); // reads next line -- should be Detection #...
    101109      if(temp.substr(0,11)!="Detection #"){
    102110        // if it is, then read two lines to finish off the file. This should trigger the eof flag above.
     
    105113      }
    106114    }
    107115
    108     std::cout<<"Final object count = "<<this->objectList->size()<<std::endl;
     116    std::cout<<"  Final object count = "<<this->objectList->size()<<std::endl;
    109117   
    110118    return SUCCESS;
    111119