about summary refs log tree commit diff stats
path: root/038---literal_strings.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-01-27 14:04:08 -0800
committerKartik Agaram <vc@akkartik.com>2020-01-27 14:04:24 -0800
commit48bde7f9214ea7fc97b14eeb51a764c3a51059a5 (patch)
treec426b5a0130095e4f639df8ad522aebd4e21a2ab /038---literal_strings.cc
parentf3c5cc53205fc8cbe6bd7a7fa9f178f8d975917b (diff)
downloadmu-48bde7f9214ea7fc97b14eeb51a764c3a51059a5.tar.gz
5935
A new error message: for unclosed string literals.
Diffstat (limited to '038---literal_strings.cc')
-rw-r--r--038---literal_strings.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/038---literal_strings.cc b/038---literal_strings.cc
index 9ae45d27..b0b3c13f 100644
--- a/038---literal_strings.cc
+++ b/038---literal_strings.cc
@@ -103,6 +103,18 @@ void test_string_literal_in_data_segment() {
   );
 }
 
+void test_string_literal_with_missing_quote() {
+  Hide_errors = true;
+  run(
+      "== code 0x1\n"
+      "b8/copy  \"test/imm32\n"
+      "== data 0x2000\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "error: unclosed string in: b8/copy  \"test/imm32"
+  );
+}
+
 :(before "End Line Parsing Special-cases(line_data -> l)")
 if (line_data.find('"') != string::npos) {  // can cause false-positives, but we can handle them
   parse_instruction_character_by_character(line_data, l);
@@ -137,7 +149,11 @@ void parse_instruction_character_by_character(const string& line_data, vector<li
       // string literal; slurp everything between quotes into data
       ostringstream d;
       d << c;
-      while (has_data(in)) {
+      while (true) {
+        if (!has_data(in)) {
+          raise << "unclosed string in: " << line_data << end();
+          return;
+        }
         in >> c;
         if (c == '\\') {
           in >> c;