From 2072fd30580a95d2fbac7939d2779a963f43e005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eliseo=20Marti=CC=81nez?= Date: Mon, 24 Nov 2014 12:35:21 +0100 Subject: [PATCH] Fix newline substitution. Problem : Command `s/\n//` is being translated into a call to do_join with a count of 1. But do_join asserts its precondition count >= 2, which is causing the program to abort. Note : This in fact revealed bigger problems: generated join command line count, as well as reported substitutions/lines were wrong in several cases, since patch 7.4.232. See: [patch] http://markmail.org/message/vo7ruair5raccawp [issue] https://code.google.com/p/vim/issues/detail?id=287 Solution : - Don't generate join command for single-line-range case. - Make generated join command include: * lines in range + 1, when range doesn't end at last line. * lines in range, when range ends at last line. - Make reported substitutions/lines always be number-of-lines-joined - 1. --- src/nvim/ex_cmds.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 556e0c01e3..0829049e4d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3602,8 +3602,13 @@ void do_sub(exarg_T *eap) eap->flags = EXFLAG_PRINT; } - do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE, true); - sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1; + linenr_T joined_lines_count = eap->line2 < curbuf->b_ml.ml_line_count + ? eap->line2 - eap->line1 + 2 + : eap->line2 - eap->line1 + 1; + if (joined_lines_count >= 2) { + do_join(joined_lines_count, FALSE, TRUE, FALSE, true); + } + sub_nlines = sub_nsubs = joined_lines_count - 1; do_sub_msg(false); ex_may_print(eap);