about summary refs log tree commit diff stats
path: root/030container.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-21 01:08:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-21 01:13:27 -0700
commit66abe7c1bd54ca227b9e035d52a1c2f1ea387b5e (patch)
tree9fc885faa5b4878247d4411bd0d72c1c59cc5f92 /030container.cc
parent22d93b76718a9e260c1969adf53fc0559cf24355 (diff)
downloadmu-66abe7c1bd54ca227b9e035d52a1c2f1ea387b5e.tar.gz
3539
Always check if next_word() returned an empty string (if it hit eof).

Thanks Rebecca Allard for running into a crash when a .mu file ends with
'{' (without a following newline).

Open question: how to express the constraint that next_word() should
always check if its result is empty? Can *any* type system do that?!
Even the usual constraint that we must use a result isn't iron-clad: you
could save the result in a variable but then ignore it. Unless you go to
Go's extraordinary lengths of considering any dead code an error.
Diffstat (limited to '030container.cc')
-rw-r--r--030container.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/030container.cc b/030container.cc
index 110a8970..6abbbcc6 100644
--- a/030container.cc
+++ b/030container.cc
@@ -721,6 +721,11 @@ Num_calls_to_transform_all_at_first_definition = -1;
 void insert_container(const string& command, kind_of_type kind, istream& in) {
   skip_whitespace_but_not_newline(in);
   string name = next_word(in);
+  if (name.empty()) {
+    assert(!has_data(in));
+    raise << "incomplete container definition at end of file (0)\n" << end();
+    return;
+  }
   // End container Name Refinements
   trace(9991, "parse") << "--- defining " << command << ' ' << name << end();
   if (!contains_key(Type_ordinal, name)
@@ -744,6 +749,11 @@ void insert_container(const string& command, kind_of_type kind, istream& in) {
   while (has_data(in)) {
     skip_whitespace_and_comments(in);
     string element = next_word(in);
+    if (element.empty()) {
+      assert(!has_data(in));
+      raise << "incomplete container definition at end of file (1)\n" << end();
+      return;
+    }
     if (element == "]") break;
     if (in.peek() != '\n') {
       raise << command << " '" << name << "' contains multiple elements on a single line. Containers and exclusive containers must only contain elements, one to a line, no code.\n" << end();