I read the possible implementation of is_permutation from <algorithm> and got a bit confused about the handling of the second range.

Code:
template <class InputIterator1, class InputIterator2>
  bool is_permutation (InputIterator1 first1, InputIterator1 last1,
                       InputIterator2 first2)
{
  std::tie (first1,first2) = std::mismatch (first1,last1,first2);
  if (first1==last1) return true;
  InputIterator2 last2 = first2; std::advance (last2,std::distance(first1,last1));
  for (InputIterator1 it1=first1; it1!=last1; ++it1) {
    if (std::find(first1,it1,*it1)==it1) {
      auto n = std::count (first2,last2,*it1);
      if (n==0 || std::count (it1,last1,*it1)!=n) return false;
    }
  }
  return true;
}

is_permuation only takes in range2.begin() and then advance the begin iter by the length of range 1. So if range 1 is longer than range 2, the advance will calculate the last2 way beyond where range.end() should be.

How come the don't take range2.end() as an argument?

When you use these function in your work, have you noticed any bug caused by this?