about summary refs log tree commit diff stats
path: root/017parse_tree.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-11-05 22:40:22 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-11-05 22:41:18 -0700
commit87196c341506ea140a1b88b74f1bb24b609d9e78 (patch)
treeeea94030106c8fd7092a7e991857d228658fea18 /017parse_tree.cc
parentbc53f46d46a08e95b424ae280a6e45b1566689fa (diff)
downloadmu-87196c341506ea140a1b88b74f1bb24b609d9e78.tar.gz
3628 - fix a segfault in parsing
Thanks Jack Couch for accidentally leading me to this bug.
Diffstat (limited to '017parse_tree.cc')
-rw-r--r--017parse_tree.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/017parse_tree.cc b/017parse_tree.cc
index eb1fb85d..50499a7c 100644
--- a/017parse_tree.cc
+++ b/017parse_tree.cc
@@ -79,10 +79,11 @@ string_tree* parse_string_tree(istream& in) {
   }
   in.get();  // skip ')'
   assert(*curr == NULL);
+  if (result->right == NULL) return result;
   // standardize the final element to always be on the right if it's an atom
   // (a b c) => (a b . c) in s-expression parlance
   string_tree* tmp = result;
-  while (tmp->right && tmp->right->right) tmp = tmp->right;
+  while (tmp->right->right) tmp = tmp->right;
   assert(!tmp->right->atom);
   if (!tmp->right->left->atom) return result;
   string_tree* tmp2 = tmp->right;
@@ -104,3 +105,9 @@ container foo [
 container bar [
 ]
 +parse:   product: {1: ("foo" ("address" "array" "character") ("bar" "number"))}
+
+:(scenario dilated_singleton_tree)
+def main [
+  {1: number, foo: (bar)} <- copy 34
+]
++parse:   product: {1: "number", "foo": ("bar")}