[Frost] changes to rootbeer src/RootBeerUtil.cxx to prevent crashes when opening empty files

Franz Klein fklein at jlab.org
Tue Sep 25 10:49:43 EDT 2012


Hi,
as mentioned during the last frost meeting, some time ago I changed the getNextFile function in /home/clasg9/rootbeer2.1/src/RootBeerUtil.cxx to prevent crashes in case that the input file is empty (or has only the BOS or ROOT header).
If you don't use the clasg9 version, please update the function (shown below) and recompile.

Cheers,
Franz

//************************* getNextFile() *****************************************
int getNextFile(char *nextfile, char *filearg){
  // get the next file
  char line[140];

  if(mode==DONT_KNOW_YET) getFileMode(filearg);

  if(mode==FROM_FILELIST){
    for(;;){                                            // scan lines from file list
      if((fgets(line,132,fp_filelist)) == NULL){
        fclose(fp_filelist);
        return -1;
      } 
      if((line[0] == '*')||(line[0] == '#')){           // skip comment lines 
        continue;
      }
      else{
        sscanf(line,"%s",nextfile);                     // get the name of the file
        struct stat fileStat;
        if(stat(nextfile,&fileStat) < 0) continue;
        //to prevent empty ROOT file (only ROOT header in file):
        if(fileStat.st_size < 400) continue;
        return ++file_no;
        break;
      }
    }
  }
    
  else{                                 // on command line
    strcpy(nextfile,filearg);           // copy the infile arg
    if(file_no>0) 
      return -1;                // only one file
    else {
      struct stat fileStat;
      if(stat(nextfile,&fileStat) < 0) return -1;
      //to prevent empty ROOT file (only ROOT header in file):
      if(fileStat.st_size < 400) return -1;
      return ++file_no;
    }
  }
  return 0;
}
//*********************************************************************************

-- 
===============================================================
                  Franz J. Klein, Associate Professor 
                  CUA, Department of Physics
                  Washington, DC 20064
  office: Hannan Hall 206          phone: 202-319-6190 
  or: Jefferson Lab,CC F-243       phone: 757-269-6672 
---------------------------------------------------------------



More information about the Frost mailing list