title: Seg Fault - Signal received, SIGABORT
body: <p>So my code compiles well, but whenever I try running the program, it seg faults. I ran it through gdb and got this set of error:</p>
  
  <pre><code>terminate called after throwing an instance of 'std::logic_error'
     what():  basic_string::_S_construct null not valid
  
  Program received signal SIGABRT, Aborted.
  0x00007ffff722bcc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
  56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
  </code></pre>
  
  <p>Here is my code if it helps:</p>
  
  <pre><code>using namespace std;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;cmath&gt;
  #include&lt;fstream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;utility&gt;
  #include &lt;string&gt;
  
  class Page
  {
    public:
      int TimeStamp;
      int ProgramOwner;
      int LocalPageNumber;
  
  };
  
  //Pair: first entry is local page, second entry is global page
  //Second entry: 1 if in main memory, 0 if not
  class Program
  {
    public:
      vector&lt; pair&lt;int,int&gt; &gt; MemoryMap;
  };
  
  class Memory
  {
    public:
      vector&lt;Program&gt; Programs;
      vector&lt;Page&gt; Pages;
  };
  
  void checkArguments(int argc, char *argv[]);
  bool checkPageAlgorithm(char *argv[]);
  bool checkPageSize(int pagesize);
  bool checkPageStyle(char *argv[]);
  bool checkPTrace(string ProgramTraceFile);
  bool checkPList(string ProgramListFile);
  
  int main(int argc, char *argv[])
  {
    //checkArguments(argc, argv);
  
    const int MemSize = 512;
    int pageSize = atoi(argv[3]);
    string programListFile = argv[1];
    string ProgramTraceFile = argv[2];
    string pageAlgorithm = argv[4];
    string pageStyle = argv[5];
    int programNumber;
    int programSize;
    int PagesNeeded;
    Memory MainMemory;
    int numberFrames;
    int pageFaults = 0;
    int numPrograms = 0;
    int PagesPerProgram;
    int LocalPage;
    int activeProgram;
    int requestedLocation;
    int newPageLocation;
    bool foundInMemory;
  
    ifstream fileIn;
    fileIn.open(programListFile.c_str());
    if(fileIn.fail())
    {
      cerr &lt;&lt; "List file not found." &lt;&lt; endl;
      fileIn.close();
      exit(1);
    }
    else
    {
      while(!fileIn.eof())
     {
        cout &lt;&lt; "hey0";
        fileIn &gt;&gt; programNumber;
        fileIn &gt;&gt; programSize;
        numPrograms++;
      }
    }
  
    numberFrames = ceil(MemSize/pageSize);
    PagesPerProgram = ceil(numberFrames/numPrograms);
    MainMemory.Pages.resize(numberFrames);  
  
    cout &lt;&lt; "hey1";
    while(!fileIn.eof())
    {
      cout &lt;&lt; "hey2";
      fileIn &gt;&gt; programNumber;
      fileIn &gt;&gt; programSize;
      cout &lt;&lt; "hey3";
      PagesNeeded = ceil(programSize/pageSize);
      for(int i = 0; i &lt; PagesNeeded; i++)
      {
        LocalPage = i;
        MainMemory.Pages[i].ProgramOwner = programNumber;
        MainMemory.Pages[i].LocalPageNumber = LocalPage; 
      }
       cout &lt;&lt; "hey3";
      if(PagesNeeded &gt; PagesPerProgram)
        PagesNeeded = PagesPerProgram;
  
      for(int i = 0; i &lt; PagesNeeded; i++)
      {
        MainMemory.Programs[programNumber].MemoryMap[i].first = MainMemory.Pages[i].LocalPageNumber;
        MainMemory.Programs[programNumber].MemoryMap[i].second = 1;
        if(pageAlgorithm == "clock")
          MainMemory.Pages[i].TimeStamp = 1;
        else
          MainMemory.Pages[i].TimeStamp = 0;
     }
    }
    fileIn.close();
  
    //LRU Algorithm Implementation
    if(pageAlgorithm == "lru")
    {
      cout &lt;&lt; "here1";
      fileIn.open(ProgramTraceFile.c_str());
      if(fileIn.fail())
      {
        cerr &lt;&lt; "That file does not exist." &lt;&lt; endl;
        fileIn.close();
        exit(1);
      }
      else
      {
        fileIn &gt;&gt; activeProgram;
        fileIn &gt;&gt; requestedLocation;
        newPageLocation = ceil(requestedLocation/pageSize);
        while(!fileIn.eof())
        {
          foundInMemory = false;
          for(int i = 0; i &lt; static_cast&lt;int&gt;(MainMemory.Programs[activeProgram].MemoryMap.size()); i++)
          {
            if((MainMemory.Programs[activeProgram].MemoryMap[i].second == 1) &amp;&amp;
           (MainMemory.Programs[activeProgram].MemoryMap[i].first == newPageLocation))
              foundInMemory = true;
            if(foundInMemory)
              break;
          }
          if(!foundInMemory)
          {
            pageFaults++;
            if(static_cast&lt;int&gt;(MainMemory.Programs[activeProgram].MemoryMap.size()) &lt; PagesPerProgram)
            {
              pair&lt;int, int&gt; temp;
              temp.first = newPageLocation;
              temp.second = 1;
              MainMemory.Programs[activeProgram].MemoryMap.push_back(temp);
            }
            else
            {
              for(int i = 0; i &lt; (static_cast&lt;int&gt;(MainMemory.Programs[activeProgram].MemoryMap.size()) - 1); i++)
              {
                if(MainMemory.Pages[i].TimeStamp &gt;= MainMemory.Pages[i+1].TimeStamp)
                {
                  MainMemory.Programs[activeProgram].MemoryMap[i].first = newPageLocation;
                }
                if(pageStyle == "1")
                {
                  if(MainMemory.Pages[i].TimeStamp &gt;= MainMemory.Pages[i+1].TimeStamp)
                  {
                    MainMemory.Programs[activeProgram].MemoryMap[i].first = MainMemory.Pages[i].LocalPageNumber; 
                  }
                }
                MainMemory.Pages[i].TimeStamp++;
              }
            }
          }
          fileIn &gt;&gt; activeProgram;
          fileIn &gt;&gt; requestedLocation;
          newPageLocation = ceil(requestedLocation/pageSize);
        }
      }
    }
  
    cout &lt;&lt; "------------------------------------" &lt;&lt; endl;
    cout &lt;&lt; "Page Size: " &lt;&lt; pageSize &lt;&lt; endl;
    cout &lt;&lt; "Page Replacement Algorithm: " &lt;&lt; pageAlgorithm &lt;&lt; endl;
    cout &lt;&lt; "Paging Style: ";
    if(pageStyle == "0")
      cout &lt;&lt; "Demand" &lt;&lt; endl;
    else
      cout &lt;&lt; "Prepaging" &lt;&lt; endl;
    cout &lt;&lt; "Number of Page Faults: " &lt;&lt; pageFaults &lt;&lt; endl;
    cout &lt;&lt; "------------------------------------" &lt;&lt; endl;
  
    return 0;
  }
  
  bool checkPList(string programlistfile)
  {
    ifstream ListFile(programlistfile.c_str());
    if(ListFile.fail())
    {
      cerr &lt;&lt; "Cannot find file " &lt;&lt; programlistfile &lt;&lt; endl;
      ListFile.close();
      return false;
    }
    else
    {
      ListFile.close();
      return true;
    }
  }
  
  bool checkPTrace(string programTraceFile)
  {
    ifstream TraceFile;
    TraceFile.open(programTraceFile.c_str());
    if(TraceFile.fail())
    {
      cerr &lt;&lt; "Cannot find file " &lt;&lt; programTraceFile &lt;&lt; endl;
      TraceFile.close();
      return false;
    }
    else
    {
      TraceFile.close();
      return true;
    }
  }
  
  bool checkPageStyle(string pageStyle)
  {
    if(pageStyle == "0")
      return true;
    else if(pageStyle == "1")
      return true;
    else
    {
      cerr &lt;&lt; "Page Style can be: 0 or 1." &lt;&lt; endl;
      return false;
    }
  }
  
  bool checkPageSize(int pagesize)
  {
    bool isValid = false;
    switch(pagesize)
    {
      case 1:
         isValid = true;
         break;
      case 2:
        isValid = true;
        break;
      case 4:
        isValid = true;
        break;
      case 8:
        isValid = true;
        break;
      case 16:
        isValid = true;
        break;
      default:
        cerr &lt;&lt; "Page Size can be: 1, 2, 4, 8, or 16." &lt;&lt; endl;
        isValid = false;
    }
    return isValid;
   }
  
  bool checkPageAlgorithm(string pageAlgorithm)
  {
    if(pageAlgorithm == "lru")
      return true;
    else if(pageAlgorithm == "fifo")
      return true;
    else if(pageAlgorithm == "clock")
      return true;
    else
    {
      cerr &lt;&lt; "Valid Page Algorithms are: lru, fifo, or clock" &lt;&lt; endl;
      return false;
    }
  }
  
  void checkArguments(int argc, char *argv[])
  {
    if(argc &lt; 6)
    {
      cerr &lt;&lt; "Invalid number of arguments. Should be: programlist programtrace pagesize pagealgorithm pagingstyle" &lt;&lt; endl;
      exit(1);
    }
  
    else if(argc &gt; 6)
    {
      cerr &lt;&lt; "Invalid number of arguments. Should be: programlist programtrace pagesize pagealgorithm pagingstyle" &lt;&lt; endl;
      exit(1);
    }
  
    else if(!checkPageAlgorithm(argv[4]))
      exit(1);
  
    else if(!checkPageSize(atoi(argv[3])))
      exit(1);
  
    else if(!checkPageStyle(argv[5]))
      exit(1);
  
    else if(!checkPTrace(argv[2]))
      exit(1);
  
    else if(!checkPList(argv[1]))
      exit(1);
  
    return;
  }
  </code></pre>
  
  <p>The output 'heys' are just to see if they get triggered within gdb, which they don't.</p>