From f730864e9fbc537fc32ecf428147b3ca68f45405 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 24 May 2016 09:15:01 -0400 Subject: [PATCH] Do a bounds check for charpos function --- cmd/micro/cursor.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index 1bb55d61..066e667a 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -18,6 +18,9 @@ func FromCharPosStart(startLoc, startX, startY, loc int, buf *Buffer) (int, int) for charNum+lineLen <= loc { charNum += lineLen y++ + if y >= buf.NumLines { + return 0, 0 + } lineLen = Count(buf.Lines[y]) + 1 } x = loc - charNum