From 2deba0cc21cfb43c22aa1300f9a000c35290c559 Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Wed, 18 Oct 2023 15:23:38 +1000 Subject: [PATCH] Fix heap error with cloning terms --- src/heap.c | 5 ++--- src/unify.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/heap.c b/src/heap.c index 1e8ba7a9d..a12cb520f 100644 --- a/src/heap.c +++ b/src/heap.c @@ -226,6 +226,7 @@ static cell *deep_clone2_to_tmp(query *q, cell *p1, pl_idx p1_ctx, unsigned dept both = 0; if (deep_copy(t)) DEREF_SLOT(both, e->vgen2, e, e->vgen, t, t_ctx, q->vgen); + if (both) q->cycle_error = true; p1 = t; p1_ctx = t_ctx; @@ -239,11 +240,10 @@ static cell *deep_clone2_to_tmp(query *q, cell *p1, pl_idx p1_ctx, unsigned dept cell *rec = deep_clone2_to_tmp(q, p1, p1_ctx, depth+1); if (!rec) return NULL; -#if 0 p1 = save_p1; p1_ctx = save_p1_ctx; - while (is_iso_list(p1)) { + while (is_iso_list(p1) && !q->cycle_error) { p1 = p1 + 1; p1 += p1->nbr_cells; cell *c = p1; pl_idx c_ctx = p1_ctx; @@ -256,7 +256,6 @@ static cell *deep_clone2_to_tmp(query *q, cell *p1, pl_idx p1_ctx, unsigned dept p1_ctx = q->latest_ctx; } } -#endif tmp = get_tmp_heap(q, save_idx); tmp->nbr_cells = tmp_heap_used(q) - save_idx; diff --git a/src/unify.c b/src/unify.c index 2cd5ecd25..ba5119a6a 100644 --- a/src/unify.c +++ b/src/unify.c @@ -1028,7 +1028,7 @@ static bool unify_lists(query *q, cell *p1, pl_idx p1_ctx, cell *p2, pl_idx p2_c p2_ctx = orig_p2_ctx; unsigned cnt = 0; - while (is_iso_list(p1) && is_iso_list(p2)) { + while (is_iso_list(p1) && is_iso_list(p2) && !q->cycle_error) { p1 = p1 + 1; p1 += p1->nbr_cells; p2 = p2 + 1; p2 += p2->nbr_cells;