patch 8.2.4956: reading past end of line with "gf" in Visual block mode
Problem: Reading past end of line with "gf" in Visual block mode.
Solution: Do not include the NUL in the length.
diff --git a/src/normal.c b/src/normal.c
index 1baf68a..bc3e29e 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -3671,9 +3671,16 @@
}
if (**pp == NUL)
*lenp = 0;
- if (has_mbyte && *lenp > 0)
- // Correct the length to include all bytes of the last character.
- *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1;
+ if (*lenp > 0)
+ {
+ if (has_mbyte)
+ // Correct the length to include all bytes of the last
+ // character.
+ *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1;
+ else if ((*pp)[*lenp - 1] == NUL)
+ // Do not include a trailing NUL.
+ *lenp -= 1;
+ }
}
reset_VIsual_and_resel();
return OK;