aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-08-28 22:09:16 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-08-30 21:12:25 -0400
commita45dc02a1421a002923a1e85214ab9d08ead9536 (patch)
treec567a69e500255e5284e371c1050a5c52602d95d /src/nvim/ex_cmds.c
parent40fca0cea8d6db8eb93059d1375630012382e465 (diff)
downloadrneovim-a45dc02a1421a002923a1e85214ab9d08ead9536.tar.gz
rneovim-a45dc02a1421a002923a1e85214ab9d08ead9536.tar.bz2
rneovim-a45dc02a1421a002923a1e85214ab9d08ead9536.zip
vim-patch:8.1.2198: crash when using :center in autocommand
Problem: Crash when using :center in autocommand. Solution: Bail out early for an empty line. (Dominique pelle, closes vim/vim#5095) https://github.com/vim/vim/commit/396b7c78c0fd9cd07528963b18c27398491df40d Cherry-pick 'src/testdir/check.vim' changes from patch 8.1.1544.
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r--src/nvim/ex_cmds.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 519978f4fb..2bac6cba58 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -326,14 +326,19 @@ static int 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 = get_cursor_line_ptr();
+ 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 && ascii_iswhite(last[-1]); --last)
- ;
+ last > first && ascii_iswhite(last[-1]); last--) {
+ }
save = *last;
*last = NUL;
// Get line length.