From 032430e396afbac6afdbb16d6a1fb0330125b923 Mon Sep 17 00:00:00 2001
From: Kragen Javier Sitaker <kragen@canonical.org>
Date: Tue, 26 Nov 2019 14:51:12 -0300
Subject: [PATCH] Fix bug #19 in permutations and sequences too

In `h_sequence__ma` the same bug occurs, and it manifests as a crash
in the same way, so I've added a test for it.  In `h_permutation__ma`
it evidently exists in the same form, but I haven't figured out how to
reproduce it; in that case I added a fix to the implementation, but no
test.
---
 src/parsers/permutation.c | 1 +
 src/parsers/sequence.c    | 1 +
 src/t_regression.c        | 9 ++++++++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/parsers/permutation.c b/src/parsers/permutation.c
index b1675841..ec256c4a 100644
--- a/src/parsers/permutation.c
+++ b/src/parsers/permutation.c
@@ -176,5 +176,6 @@ HParser* h_permutation__ma(HAllocator* mm__, void *args[]) {
   ret->vtable = &permutation_vt; 
   ret->env = (void*)s;
   ret->backend = PB_MIN;
+  ret->desugared = NULL;
   return ret;
 }
diff --git a/src/parsers/sequence.c b/src/parsers/sequence.c
index 55c0c888..5ca034ad 100644
--- a/src/parsers/sequence.c
+++ b/src/parsers/sequence.c
@@ -171,5 +171,6 @@ HParser* h_sequence__ma(HAllocator* mm__, void *args[]) {
   ret->vtable = &sequence_vt; 
   ret->env = (void*)s; 
   ret->backend = PB_MIN;
+  ret->desugared = NULL;
   return ret;
 }
diff --git a/src/t_regression.c b/src/t_regression.c
index 60ba8638..4e8ad0cd 100644
--- a/src/t_regression.c
+++ b/src/t_regression.c
@@ -259,7 +259,14 @@ static void test_bug_19() {
     // it, leading to a crash immediately afterwards in collect_nts.
     // We don't actually care if the compile succeeds or fails, just
     // that it doesn't crash.
-    int compile_result = h_compile(parser, PB_GLR, NULL);
+    h_compile(parser, PB_GLR, NULL);
+
+    // The same bug happened in h_sequence__ma.
+    h_compile(h_sequence__ma(&deadbeefing_allocator, args), PB_GLR, NULL);
+
+    // It also exists in h_permutation__ma, but it doesn't happen to
+    // manifest in the same way.  I don't know how to write a test for
+    // the h_permutation__ma case.
     g_assert_true(1);
 }
 
-- 
GitLab