From cf6e5fec6340f5b2da8f1714ae8739b50e1ab82a Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Wed, 16 Jul 2025 09:59:48 -0400 Subject: [PATCH] Fix unterminated strings in linkerscripts consuming their newline --- src/link/script.y | 4 +++- test/link/script-unterminated-string.link | 3 +++ test/link/script-unterminated-string.out | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/link/script.y b/src/link/script.y index 84aa5e30..6cd4ecca 100644 --- a/src/link/script.y +++ b/src/link/script.y @@ -306,7 +306,9 @@ yy::parser::symbol_type yylex() { } str.push_back(c); } - context.file.sbumpc(); // Consume the closing quote. + if (c == '"') { + context.file.sbumpc(); + } return yy::parser::make_string(std::move(str)); } else if (c == '$') { diff --git a/test/link/script-unterminated-string.link b/test/link/script-unterminated-string.link index ab5d7ee1..2c3f28f6 100644 --- a/test/link/script-unterminated-string.link +++ b/test/link/script-unterminated-string.link @@ -1,2 +1,5 @@ rom0 "ROM0 +romx 2 + "ROM2 1K + "ROM2 1 diff --git a/test/link/script-unterminated-string.out b/test/link/script-unterminated-string.out index b84820ff..a7f1ead9 100644 --- a/test/link/script-unterminated-string.out +++ b/test/link/script-unterminated-string.out @@ -1,2 +1,4 @@ error: script-unterminated-string.link(2): Unterminated string -Linking failed with 1 error +error: script-unterminated-string.link(4): Unterminated string +error: script-unterminated-string.link(5): Unterminated string +Linking failed with 3 errors