patch 9.1.1303: missing out-of-memory check in linematch.c
Commit:
https://github.com/vim/vim/commit/2137710b436e481168382c50aa4838a4b9730163
Author: John Marriott <[email protected]>
Date: Tue Apr 15 18:15:24 2025 +0200
patch 9.1.1303: missing out-of-memory check in linematch.c
Problem: missing out-of-memory check in linematch.c
Solution: return early in case of memory allocation failure, move the
pow() calculation ouside of the for() loop
(John Marriott)
closes: #17118
Signed-off-by: John Marriott <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/linematch.c b/src/linematch.c
index 17e932d00..1fab28276 100644
--- a/src/linematch.c
+++ b/src/linematch.c
@@ -410,12 +410,16 @@ linematch_nbuffers(
// create the flattened path matrix
diffcmppath_T *diffcmppath = lalloc(sizeof(diffcmppath_T) * memsize, TRUE);
+ if (diffcmppath == NULL)
+ return 0;
+
// allocate memory here
+ size_t n = (size_t)pow(2.0, (double)ndiffs);
for (size_t i = 0; i < memsize; i++)
{
diffcmppath[i].df_lev_score = 0;
diffcmppath[i].df_path_n = 0;
- for (size_t j = 0; j < (size_t)pow(2, (double)ndiffs); j++)
+ for (size_t j = 0; j < n; j++)
diffcmppath[i].df_choice_mem[j] = -1;
}
@@ -428,6 +432,12 @@ linematch_nbuffers(
diffcmppath_T *startNode = &diffcmppath[u];
*decisions = lalloc(sizeof(int) * memsize_decisions, TRUE);
+ if (*decisions == NULL)
+ {
+ vim_free(diffcmppath);
+ return 0;
+ }
+
size_t n_optimal = 0;
test_charmatch_paths(startNode, 0);
while (startNode->df_path_n > 0)
diff --git a/src/version.c b/src/version.c
index 90ddf0bab..e2314ca12 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1303,
/**/
1302,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1u4jAl-004nXY-HB%40256bit.org.