From f5c1314cb01164879fb9df6bce01151371c16f7d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 31 May 2020 12:06:47 -0400 Subject: vim-patch:8.2.0089: crash when running out of memory in :setfiletype completion Problem: Crash when running out of memory in :setfiletype completion. Solution: Do not allocate memory. (Dominique Pelle, closes vim/vim#5438) https://github.com/vim/vim/commit/f0f8055102c264b1d0c0a79bf742dc126fb447b9 --- src/nvim/ex_getln.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b799e86ff7..56a8f56753 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -5361,12 +5361,12 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options) // Concatenate new results to previous ones. ga_grow(ga, num_p); + // take over the pointers and put them in "ga" for (int i = 0; i < num_p; i++) { - ((char_u **)ga->ga_data)[ga->ga_len] = vim_strsave(p[i]); + ((char_u **)ga->ga_data)[ga->ga_len] = p[i]; ga->ga_len++; } - - FreeWild(num_p, p); + xfree(p); } } } -- cgit From 2298350884b09e1af45859da23c89d072f7de99b Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 31 May 2020 14:58:46 -0400 Subject: vim-patch:8.1.0917: double free when running out of memory Problem: Double free when running out of memory. Solution: Remove one free. (Ken Takata, closes vim/vim#3955) https://github.com/vim/vim/commit/445e71c5ee06015064cf0642cac8190cfe8fbc59 --- src/nvim/eval/userfunc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index c054433255..4d658498c1 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -170,6 +170,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) garray_T newargs = GA_EMPTY_INIT_VALUE; garray_T *pnewargs; ufunc_T *fp = NULL; + partial_T *pt = NULL; int varargs; int ret; char_u *start = skipwhite(*arg + 1); @@ -219,7 +220,6 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) int len, flags = 0; char_u *p; char_u name[20]; - partial_T *pt; garray_T newlines; lambda_no++; @@ -274,6 +274,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) errret: ga_clear_strings(&newargs); xfree(fp); + xfree(pt); eval_lavars_used = old_eval_lavars; return FAIL; } -- cgit From 64a2884d4cc78e3bbf1632cfe18d9e60a787a93e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 31 May 2020 15:53:37 -0400 Subject: vim-patch:8.0.1564: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate the +autocmd feature. Takes away 450 #ifdefs and increases code size of tiny Vim by only 40 Kbyte. https://github.com/vim/vim/commit/f2bd8ef2b4507d02c6043affff8f7e85e3414d5f --- src/nvim/globals.h | 2 ++ src/nvim/main.c | 7 ++++--- src/nvim/os/signal.c | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/globals.h b/src/nvim/globals.h index f102c3ddd8..08a217a6e8 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -478,6 +478,8 @@ EXTERN int sc_col; // column for shown command EXTERN int starting INIT(= NO_SCREEN); // true when planning to exit. Might keep running if there is a changed buffer. EXTERN bool exiting INIT(= false); +// internal value of v:dying +EXTERN int v_dying INIT(= 0); // is stdin a terminal? EXTERN int stdin_isatty INIT(= true); // is stdout a terminal? diff --git a/src/nvim/main.c b/src/nvim/main.c index 6ac9cdfbae..b3a903cbe3 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -621,7 +621,7 @@ void getout(int exitval) /* Optionally print hashtable efficiency. */ hash_debug_results(); - if (get_vim_var_nr(VV_DYING) <= 1) { + if (v_dying <= 1) { const tabpage_T *next_tp; // Trigger BufWinLeave for all windows, but only once per buffer. @@ -670,8 +670,9 @@ void getout(int exitval) shada_write_file(NULL, false); } - if (get_vim_var_nr(VV_DYING) <= 1) - apply_autocmds(EVENT_VIMLEAVE, NULL, NULL, FALSE, curbuf); + if (v_dying <= 1) { + apply_autocmds(EVENT_VIMLEAVE, NULL, NULL, false, curbuf); + } profile_dump(); diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 112de9fed8..bfe230b521 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -157,6 +157,7 @@ static void deadly_signal(int signum) { // Set the v:dying variable. set_vim_var_nr(VV_DYING, 1); + v_dying = 1; WLOG("got signal %d (%s)", signum, signal_name(signum)); -- cgit From 310a56d0a05deceea7df5a74f418f1df322ec9e1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 31 May 2020 16:17:45 -0400 Subject: vim-patch:8.1.1895: using NULL pointer when out of memory Problem: Using NULL pointer when out of memory. Solution: Bail out or skip the code using the pointer. (Zu-Ming Jiang, closes vim/vim#4805, closes vim/vim#4843, closes vim/vim#4939, closes vim/vim#4844) https://github.com/vim/vim/commit/6f10c70b59fa4e56aa479345fb0caeaac7429bfb --- src/nvim/buffer.c | 11 +++++++---- src/nvim/syntax.c | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 7c8f93163a..3ce39feda5 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -186,14 +186,17 @@ int open_buffer( } } - /* - * if there is no memfile at all, exit - * This is OK, since there are no changes to lose. - */ + // If there is no memfile at all, exit. + // This is OK, since there are no changes to lose. if (curbuf == NULL) { EMSG(_("E82: Cannot allocate any buffer, exiting...")); + + // Don't try to do any saving, with "curbuf" NULL almost nothing + // will work. + v_dying = 2; getout(2); } + EMSG(_("E83: Cannot allocate buffer, using other one...")); enter_buffer(curbuf); if (old_tw != curbuf->b_p_tw) { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index ef4dfb3caa..f3b05c3961 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -7444,6 +7444,8 @@ static int syn_add_group(char_u *name) return 0; } + char_u *const name_up = vim_strsave_up(name); + // Append another syntax_highlight entry. struct hl_group* hlgp = GA_APPEND_VIA_PTR(struct hl_group, &highlight_ga); memset(hlgp, 0, sizeof(*hlgp)); @@ -7452,7 +7454,7 @@ static int syn_add_group(char_u *name) hlgp->sg_rgb_fg = -1; hlgp->sg_rgb_sp = -1; hlgp->sg_blend = -1; - hlgp->sg_name_u = vim_strsave_up(name); + hlgp->sg_name_u = name_up; return highlight_ga.ga_len; /* ID is index plus one */ } -- cgit From 44531928b3512b143f6e3c958e49f99e827eb7de Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 31 May 2020 17:01:28 -0400 Subject: vim-patch:8.1.2018: using freed memory when out of memory and displaying message Problem: Using freed memory when out of memory and displaying message. Solution: Make a copy of the message first. https://github.com/vim/vim/commit/e5fbd7393067c279860598ac8359d1617b1082b9 --- src/nvim/globals.h | 2 +- src/nvim/message.c | 5 ----- src/nvim/normal.c | 15 +++++++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 08a217a6e8..d6d00d6e83 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -203,7 +203,7 @@ EXTERN int msg_nowait INIT(= false); // don't wait for this msg EXTERN int emsg_off INIT(= 0); // don't display errors for now, // unless 'debug' is set. EXTERN int info_message INIT(= false); // printing informative message -EXTERN int msg_hist_off INIT(= false); // don't add messages to history +EXTERN bool msg_hist_off INIT(= false); // don't add messages to history EXTERN int need_clr_eos INIT(= false); // need to clear text before // displaying a message. EXTERN int emsg_skip INIT(= 0); // don't display errors for diff --git a/src/nvim/message.c b/src/nvim/message.c index 9aa588e035..8999365d32 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -306,11 +306,6 @@ bool msg_attr_keep(char_u *s, int attr, bool keep, bool multiline) add_msg_hist((const char *)s, -1, attr, multiline); } - /* When displaying keep_msg, don't let msg_start() free it, caller must do - * that. */ - if (s == keep_msg) - keep_msg = NULL; - /* Truncate the message if needed. */ msg_start(); buf = msg_strtrunc(s, FALSE); diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 87d687198d..968cfde388 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -621,6 +621,8 @@ static void normal_redraw_mode_message(NormalState *s) update_screen(0); // now reset it, otherwise it's put in the history again keep_msg = kmsg; + + kmsg = vim_strsave(keep_msg); msg_attr((const char *)kmsg, keep_msg_attr); xfree(kmsg); } @@ -1265,10 +1267,15 @@ static void normal_redraw(NormalState *s) // Display message after redraw. If an external message is still visible, // it contains the kept message already. if (keep_msg != NULL && !msg_ext_is_visible()) { - // msg_attr_keep() will set keep_msg to NULL, must free the string here. - // Don't reset keep_msg, msg_attr_keep() uses it to check for duplicates. - char *p = (char *)keep_msg; - msg_attr(p, keep_msg_attr); + char_u *const p = vim_strsave(keep_msg); + + // msg_start() will set keep_msg to NULL, make a copy + // first. Don't reset keep_msg, msg_attr_keep() uses it to + // check for duplicates. Never put this message in + // history. + msg_hist_off = true; + msg_attr((const char *)p, keep_msg_attr); + msg_hist_off = false; xfree(p); } -- cgit From f85bf6ec374edbfbee35be2112840e0c6d011ca2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 2 Jun 2020 23:52:41 -0400 Subject: vim-patch:8.2.0873: a .jl file can be sawfish (lisp) or Julia Problem: A .jl file can be sawfish (lisp) or Julia. Solution: Do not recognize *.jl as lisp, since it might be Julia. (closes vim/vim#6178) https://github.com/vim/vim/commit/2891459b81a21dbd2802ef1ae106c6680f085899 --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 832f1726fb..ffd2cee80f 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -252,7 +252,7 @@ let s:filename_checks = { \ 'lilo': ['lilo.conf'], \ 'limits': ['/etc/limits', '/etc/anylimits.conf', '/etc/anylimits.d/file.conf'], \ 'liquid': ['file.liquid'], - \ 'lisp': ['sbclrc', '.sbclrc'], + \ 'lisp': ['file.lsp', 'file.lisp', 'file.el', 'file.cl', '.emacs', '.sawfishrc', 'sbclrc', '.sbclrc'], \ 'lite': ['file.lite', 'file.lt'], \ 'litestep': ['/LiteStep/any/file.rc'], \ 'loginaccess': ['/etc/login.access'], -- cgit From 909af2f3f10b49faf5f56ca866d316dbb0a94384 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 3 Jun 2020 01:36:26 -0400 Subject: vim-patch:8.2.0491: cannot recognize a