]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1691: over-allocation in ga_concat_strings() v9.1.1691
authorDamien Lejay <damien@lejay.be>
Tue, 26 Aug 2025 15:55:14 +0000 (17:55 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 26 Aug 2025 15:55:14 +0000 (17:55 +0200)
Problem:  over-allocation in ga_concat_strings()
Solution: Fix ga_concat_strings() and only allocate n-1 separator length
          bytes (Damien Lejay).

ga_concat_strings() was adding the separator length for every item,
including the last one. Only (n - 1) separators are actually used.
This caused harmless but unnecessary overallocation.

closes: #18112

Signed-off-by: Damien Lejay <damien@lejay.be>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/alloc.c
src/version.c

index 5f39085bce258d1011c7a7ddf61826830fcae8b5..386964c5b6ed1efef3b8c748a06bdc20ba2c9572 100644 (file)
@@ -770,7 +770,10 @@ ga_concat_strings(garray_T *gap, char *sep)
     char_u     *p;
 
     for (i = 0; i < gap->ga_len; ++i)
-       len += (int)STRLEN(((char_u **)(gap->ga_data))[i]) + sep_len;
+       len += (int)STRLEN(((char_u **)(gap->ga_data))[i]);
+
+    if (gap->ga_len > 1)
+       len += (gap->ga_len - 1) * sep_len;
 
     s = alloc(len + 1);
     if (s == NULL)
index b0ce4f31108a0986cfb3a8fee627c08fdb325315..db3a4b7ac35c299bc16b4463f6c933eeb153706a 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1691,
 /**/
     1690,
 /**/