Mercurial > vim
comparison src/ex_cmds.c @ 18408:50c0a9fb07ae v8.1.2198
patch 8.1.2198: crash when using :center in autocommand
Commit: https://github.com/vim/vim/commit/396b7c78c0fd9cd07528963b18c27398491df40d
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Oct 21 23:08:59 2019 +0200
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 https://github.com/vim/vim/issues/5095)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 21 Oct 2019 23:15:03 +0200 |
parents | ba5d8c5d77d7 |
children | 967ca19425e3 |
comparison
equal
deleted
inserted
replaced
18407:3f9986aeb41a | 18408:50c0a9fb07ae |
---|---|
249 char_u *first; | 249 char_u *first; |
250 char_u *last; | 250 char_u *last; |
251 int save; | 251 int save; |
252 int len; | 252 int len; |
253 | 253 |
254 /* find the first non-blank character */ | 254 // Get the line. If it's empty bail out early (could be the empty string |
255 // for an unloaded buffer). | |
255 line = ml_get_curline(); | 256 line = ml_get_curline(); |
257 if (*line == NUL) | |
258 return 0; | |
259 | |
260 // find the first non-blank character | |
256 first = skipwhite(line); | 261 first = skipwhite(line); |
257 | 262 |
258 /* find the character after the last non-blank character */ | 263 // find the character after the last non-blank character |
259 for (last = first + STRLEN(first); | 264 for (last = first + STRLEN(first); |
260 last > first && VIM_ISWHITE(last[-1]); --last) | 265 last > first && VIM_ISWHITE(last[-1]); --last) |
261 ; | 266 ; |
262 save = *last; | 267 save = *last; |
263 *last = NUL; | 268 *last = NUL; |
264 len = linetabsize(line); /* get line length */ | 269 len = linetabsize(line); // get line length |
265 if (has_tab != NULL) /* check for embedded TAB */ | 270 if (has_tab != NULL) // check for embedded TAB |
266 *has_tab = (vim_strchr(first, TAB) != NULL); | 271 *has_tab = (vim_strchr(first, TAB) != NULL); |
267 *last = save; | 272 *last = save; |
268 | 273 |
269 return len; | 274 return len; |
270 } | 275 } |