diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-21 01:08:09 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-21 01:13:27 -0700 |
commit | 66abe7c1bd54ca227b9e035d52a1c2f1ea387b5e (patch) | |
tree | 9fc885faa5b4878247d4411bd0d72c1c59cc5f92 /089scenario_filesystem.cc | |
parent | 22d93b76718a9e260c1969adf53fc0559cf24355 (diff) | |
download | mu-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 '089scenario_filesystem.cc')
-rw-r--r-- | 089scenario_filesystem.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/089scenario_filesystem.cc b/089scenario_filesystem.cc index c761ee93..6af3166b 100644 --- a/089scenario_filesystem.cc +++ b/089scenario_filesystem.cc @@ -115,6 +115,11 @@ void parse_resources(const string& data, map<string, string>& out, const string& skip_whitespace_and_comments(in); if (!has_data(in)) break; string filename = next_word(in); + if (filename.empty()) { + assert(!has_data(in)); + raise << "incomplete 'resources' block at end of file (0)\n" << end(); + return; + } if (*filename.begin() != '[') { raise << caller << ": assume-resources: filename '" << filename << "' must begin with a '['\n" << end(); break; @@ -130,6 +135,11 @@ void parse_resources(const string& data, map<string, string>& out, const string& break; } string arrow = next_word(in); + if (arrow.empty()) { + assert(!has_data(in)); + raise << "incomplete 'resources' block at end of file (1)\n" << end(); + return; + } if (arrow != "<-") { raise << caller << ": assume-resources: expected '<-' after filename '" << filename << "' but got '" << arrow << "'\n" << end(); break; @@ -139,6 +149,11 @@ void parse_resources(const string& data, map<string, string>& out, const string& break; } string contents = next_word(in); + if (contents.empty()) { + assert(!has_data(in)); + raise << "incomplete 'resources' block at end of file (2)\n" << end(); + return; + } if (*contents.begin() != '[') { raise << caller << ": assume-resources: file contents '" << contents << "' for filename '" << filename << "' must begin with a '['\n" << end(); break; |