title: basic_string::_M_construct null not valid after constructing subvector of strings
body: <p>My code is supposed to read in a text file and have multiple threads look through different chunks of lines for the longest palindrome. The size of the chunk (how many lines) is determined by a variable number of threads passed in as an argument. The original text file is stored in an std::vector where each index of the vector corresponds to the original file.</p>
  
  <p>When I pass the subvector chunk to findPalindome(), I get a 'C++ basic_string::_M_construct null not valid' and I can't figure out why. None of my strings should be NULL.</p>
  
  <p>When I pass original vector lines I get no errors so I'm assuming it has to do with how I'm creating the subvector.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>Result longestPalindrome(std::string str)
  {
  
      int maxLength = 1;  // The result (length of LPS)
      int start = 0;
      int len = str.size();
      int low, high;
  
      // One by one consider every character as center point of 
      // even and length palindromes
      for (int i = 1; i &lt; len; ++i)
      {
          // Find the longest even length palindrome with center points
          // as i-1 and i.  
          low = i - 1;
          high = i;
          while (low &gt;= 0 &amp;&amp; high &lt; len &amp;&amp; str[low] == str[high])
          {
              if (high - low + 1 &gt; maxLength)
              {
                  start = low;
                  maxLength = high - low + 1;
              }
              --low;
              ++high;
          }
  
          // Find the longest odd length palindrome with center 
          // point as i
          low = i - 1;
          high = i + 1;
          while (low &gt;= 0 &amp;&amp; high &lt; len &amp;&amp; str[low] == str[high])
          {
               if (high - low + 1 &gt; maxLength)
               {
                  start = low;
                  maxLength = high - low + 1;
               }
               --low;
              ++high;
          }
      }
      Result result = {0, 0, 0};
      return result;
  }
  
  void findPalindome(std::vector&lt;std::string&gt; chunk, Result&amp; result)
  {
      Result localLargest = {0,0,0};
      for (unsigned int i = 0; i &lt; chunk.size(); i++)
      {
          Result loopLargest = longestPalindrome(chunk[i]);
          if (localLargest &lt; loopLargest)
          {
              localLargest = loopLargest;
          }
      }
      result = localLargest;
  }
  
  Result
  FindPalindromeStatic(Lines const&amp; lines, int numThreads)
  {
      std::vector&lt;Result&gt; results(numThreads, {0,0,0});;
      int chunkSize = lines.size() / numThreads; //lines is the original vector with all the lines in the file
      std::vector&lt;std::thread&gt; threads;
      int counter = 0;
      for (int i = 0; i &lt; numThreads; i++)
      {
          std::vector&lt;std::string&gt;::const_iterator begin = lines.begin() + counter;
          std::vector&lt;std::string&gt;::const_iterator end = lines.begin() + ((i + 1) * chunkSize);
          std::vector&lt;std::string&gt; chunk(begin, end);
          threads.emplace_back(&amp;findPalindome, std::ref(chunk), std::ref(results[i]));
          counter = ((i+1)*chunkSize);
      }
      for (int i = 0; i &lt; numThreads; i++)
      {
          threads[i].join();
      }
      Result x = {0,0,0};
      return x;
  }
  </code></pre>
  
  <p>Any help would be appreciated and this is my first stack question so sorry for any mistakes.</p>