From 345e88eb68a73084784e379faa693ff8f859bb2a Mon Sep 17 00:00:00 2001 From: megidont Date: Thu, 5 Nov 2020 15:01:03 -0600 Subject: [PATCH] Added failsafe to catch linter trying to put cursor out of bounds. Signed-off-by: megidont --- src/text.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/text.c b/src/text.c index 79bc026d..1997c362 100644 --- a/src/text.c +++ b/src/text.c @@ -2823,7 +2823,19 @@ void do_linter(void) } if (tmplint != curlint) { - goto_line_posx(curlint->lineno, curlint->colno - 1); + /*check if line or column number are out of bounds, move to position if not*/ + if((curlint->lineno - 1) < openfile->filebot->lineno){ + goto_line_posx(curlint->lineno, 0); + const char* currentLineData = openfile->current->data; + if(curlint->colno - 2 < mbstrlen(currentLineData)){ + goto_line_posx(curlint->lineno, curlint->colno - 1); + }else{ + statusline(ALERT, "Linter specified out of bounds column: %zu", curlint->colno); + } + }else{ + /*I'd rather go to the start of the document than segfault*/ + statusline(ALERT, "Linter specified out of bounds line: %zu", curlint->lineno); + } titlebar(NULL); adjust_viewport(CENTERING); #ifdef ENABLE_LINENUMBERS -- 2.25.1