From 01cbb584be17ea3ace4910678c35795e6931e731 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Tue, 5 Jul 2016 19:00:27 +0200 Subject: [PATCH] Guard against invalid positions --- SwiftNeoVim/Grid.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/SwiftNeoVim/Grid.swift b/SwiftNeoVim/Grid.swift index 2f74ba85..5283c620 100644 --- a/SwiftNeoVim/Grid.swift +++ b/SwiftNeoVim/Grid.swift @@ -198,6 +198,10 @@ class Grid: CustomStringConvertible { } func isCellEmpty(position: Position) -> Bool { + guard self.isSane(position: position) else { + return false + } + if self.cells[position.row][position.column].string.characters.count == 0 { return true } @@ -241,4 +245,12 @@ class Grid: CustomStringConvertible { self.cells[i].replaceRange(region.left...region.right, with: clearedRow) } } + + private func isSane(position position: Position) -> Bool { + guard position.row < self.size.height && position.column < self.size.width else { + return false + } + + return true + } }