From 413660496bf0f4140ab7cb35c458b68e54d7451b Mon Sep 17 00:00:00 2001 From: mivirl <> Date: Tue, 14 Jan 2025 13:49:05 +0000 Subject: [PATCH] Apply patch from udif to diff-match-patch-c Fixes an infinite loop under some situations Patch: https://github.com/arrbee/diff-match-patch-c/pull/6 --- ext/diff-match-patch-c/src/dmp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/diff-match-patch-c/src/dmp.c b/ext/diff-match-patch-c/src/dmp.c index 260b907..f3c2bc5 100644 --- a/ext/diff-match-patch-c/src/dmp.c +++ b/ext/diff-match-patch-c/src/dmp.c @@ -372,7 +372,7 @@ static int diff_bisect( static int diff_cleanup_merge(dmp_diff *diff, dmp_range *list) { dmp_pool *pool = &diff->pool; - int i, before, common, changes; + int i, j, before, common, changes; int count_delete, count_insert, len_delete, len_insert; dmp_node *ins = NULL, *del = NULL, *last = NULL, *node, *next; @@ -393,8 +393,9 @@ static int diff_cleanup_merge(dmp_diff *diff, dmp_range *list) * that can be extracted */ - for (i = list->start; i != -1; i = node->next) { + for (i = list->start; i != -1; i = j) { node = dmp_node_at(pool, i); + j = node->next; switch (node->op) { case DMP_DIFF_INSERT: -- 2.39.5