patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem: More code can use ml_get_buf_len() instead of STRLEN().
Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not
set ml_line_textlen in ml_replace_len() if "has_props" is set,
because "len_arg" also includes the size of text properties in
that case. (zeertzjq)
closes: #14183
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index a12d819..d0fc928 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -489,7 +489,7 @@
for (lnum = eap->line1; lnum <= eap->line2; ++lnum)
{
s = ml_get(lnum);
- len = (int)STRLEN(s);
+ len = ml_get_len(lnum);
if (maxlen < len)
maxlen = len;
@@ -691,7 +691,7 @@
return FAIL;
for (extra = 0, l = line1; l <= line2; l++)
{
- str = vim_strsave(ml_get(l + extra));
+ str = vim_strnsave(ml_get(l + extra), ml_get_len(l + extra));
if (str != NULL)
{
ml_append(dest + l - line1, str, (colnr_T)0, FALSE);
@@ -824,9 +824,9 @@
curwin->w_cursor.lnum = n;
while (line1 <= line2)
{
- // need to use vim_strsave() because the line will be unlocked within
+ // need to make a copy because the line will be unlocked within
// ml_append()
- p = vim_strsave(ml_get(line1));
+ p = vim_strnsave(ml_get(line1), ml_get_len(line1));
if (p != NULL)
{
ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE);
@@ -4225,7 +4225,8 @@
if (sub_firstline == NULL)
{
- sub_firstline = vim_strsave(ml_get(sub_firstlnum));
+ sub_firstline = vim_strnsave(ml_get(sub_firstlnum),
+ ml_get_len(sub_firstlnum));
if (sub_firstline == NULL)
{
vim_free(new_start);
@@ -4379,7 +4380,8 @@
// really update the line, it would change
// what matches. Temporarily replace the line
// and change it back afterwards.
- orig_line = vim_strsave(ml_get(lnum));
+ orig_line = vim_strnsave(ml_get(lnum),
+ ml_get_len(lnum));
if (orig_line != NULL)
{
char_u *new_line = concat_str(new_start,
@@ -4725,7 +4727,8 @@
{
sub_firstlnum += nmatch - 1;
vim_free(sub_firstline);
- sub_firstline = vim_strsave(ml_get(sub_firstlnum));
+ sub_firstline = vim_strnsave(ml_get(sub_firstlnum),
+ ml_get_len(sub_firstlnum));
// When going beyond the last line, stop substituting.
if (sub_firstlnum <= line2)
do_again = TRUE;