A range is a location
and a length
, not a start and end position.
typedef struct _NSRange {
NSUInteger location;
NSUInteger length;
} NSRange;
So with a start location of 2
and a length of 3
you overrun the end.
Change the range based on the correct specification.