diff src/memline.c @ 34518:80991201ed38 v9.1.0163

patch 9.1.0163: Calling STRLEN() to compute ml_line_textlen when not needed Commit: https://github.com/vim/vim/commit/82e079df814f7372e9579450730062b205449efa Author: zeertzjq <zeertzjq@outlook.com> Date: Sun Mar 10 08:55:42 2024 +0100 patch 9.1.0163: Calling STRLEN() to compute ml_line_textlen when not needed Problem: Calling STRLEN() to compute ml_line_textlen when not needed. Solution: Use 0 when STRLEN() will be required and call STRLEN() later. (zeertzjq) closes: #14155 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 10 Mar 2024 09:00:08 +0100
parents 67674e379c26
children 64edf95a833a
line wrap: on
line diff
--- a/src/memline.c
+++ b/src/memline.c
@@ -2700,9 +2700,13 @@ ml_get_cursor_len(void)
     colnr_T
 ml_get_buf_len(buf_T *buf, linenr_T lnum)
 {
-    if (*ml_get_buf(buf, lnum, FALSE) == NUL)
+    char_u	*line;
+
+    if (*(line = ml_get_buf(buf, lnum, FALSE)) == NUL)
         return 0;
 
+    if (buf->b_ml.ml_line_textlen <= 0)
+	buf->b_ml.ml_line_textlen = (int)STRLEN(line) + 1;
     return buf->b_ml.ml_line_textlen - 1;
 }
 
@@ -2799,8 +2803,11 @@ errorret:
 	buf->b_ml.ml_line_ptr = (char_u *)dp + start;
 	buf->b_ml.ml_line_len = end - start;
 #if defined(FEAT_BYTEOFF) && defined(FEAT_PROP_POPUP)
-	if (buf->b_has_textprop)
-	    buf->b_ml.ml_line_textlen = (int)STRLEN(buf->b_ml.ml_line_ptr) + 1;
+	// Text properties come after a NUL byte, so ml_line_len should be
+	// larger than the size of textprop_T if there is any.
+	if (buf->b_has_textprop
+			 && (size_t)buf->b_ml.ml_line_len > sizeof(textprop_T))
+	    buf->b_ml.ml_line_textlen = 0;  // call STRLEN() later when needed
 	else
 #endif
 	    buf->b_ml.ml_line_textlen = buf->b_ml.ml_line_len;