summaryrefslogtreecommitdiff
path: root/src/ex_cmds.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-10-21 23:08:59 +0200
committerBram Moolenaar <Bram@vim.org>2019-10-21 23:08:59 +0200
commit396b7c78c0fd9cd07528963b18c27398491df40d (patch)
tree34e4afda06906bd4fb7662c4ea9adb02a670fa6f /src/ex_cmds.c
parent34ba06b6e6f94bb46062e6c85dbfdcbb0d255ada (diff)
downloadvim-git-396b7c78c0fd9cd07528963b18c27398491df40d.tar.gz
patch 8.1.2198: crash when using :center in autocommandv8.1.2198
Problem: Crash when using :center in autocommand. Solution: Bail out early for an empty line. (Dominique pelle, closes #5095)
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r--src/ex_cmds.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index bcff7ee71..e472c8a6f 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -251,18 +251,23 @@ linelen(int *has_tab)
int save;
int len;
- /* find the first non-blank character */
+ // Get the line. If it's empty bail out early (could be the empty string
+ // for an unloaded buffer).
line = ml_get_curline();
+ if (*line == NUL)
+ return 0;
+
+ // find the first non-blank character
first = skipwhite(line);
- /* find the character after the last non-blank character */
+ // find the character after the last non-blank character
for (last = first + STRLEN(first);
last > first && VIM_ISWHITE(last[-1]); --last)
;
save = *last;
*last = NUL;
- len = linetabsize(line); /* get line length */
- if (has_tab != NULL) /* check for embedded TAB */
+ len = linetabsize(line); // get line length
+ if (has_tab != NULL) // check for embedded TAB
*has_tab = (vim_strchr(first, TAB) != NULL);
*last = save;