How does your function know the length of the array? You seem to be accessing memory that does not belong to you which I why I believe the OS is complaining
Smac89: The code follows the convention of first == the first element in the sequence, last == one past the last element in the sequence, so length == last - first.
arvust: Your check on line 17 is backwards. It should be last - first <= 1.
As a matter of convention, use the names begin and end in the future. 'Last' is a misnomer, since the pointer doesn't point to the last element in the sequence.