It seems to be a bug in search_n, it crashes for me too (Xcode 4.6.1). I think in __search_n the test
if (__first == __s) // return __last if no element matches __value_
needs to be
if (__first >= __s) // return __last if no element matches __value_
What happens is that the algorithm starts matching, then mismatches and starts over; this new startpoint is beyond __s which is the logical last possible starting point for the length of the pattern. The old test only tested for equality, not "beyondness". With the fix it doesn't crash for me any more.