Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested undefined interpolation segfault #1542

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/asm/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,9 @@ static int peek() {
} else if (c == '{' && !lexerState->disableInterpolation) {
// If character is an open brace, do symbol interpolation
shiftChar();

if (auto str = readInterpolation(0); str) {
beginExpansion(str, *str);
}

return peek();
}

Expand Down Expand Up @@ -1201,9 +1199,9 @@ static std::shared_ptr<std::string> readInterpolation(size_t depth) {

if (c == '{') { // Nested interpolation
shiftChar();
auto str = readInterpolation(depth + 1);

beginExpansion(str, *str);
if (auto str = readInterpolation(depth + 1); str) {
beginExpansion(str, *str);
}
continue; // Restart, reading from the new buffer
} else if (c == EOF || c == '\r' || c == '\n' || c == '"') {
error("Missing }\n");
Expand Down
3 changes: 3 additions & 0 deletions test/asm/nested-bad-interpolation.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def p = {{a}}
def q = "{b}"
def r = "{{c}}"
17 changes: 17 additions & 0 deletions test/asm/nested-bad-interpolation.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: nested-bad-interpolation.asm(1):
Interpolated symbol "a" is a reserved keyword; add a '#' prefix to use it as a raw symbol
error: nested-bad-interpolation.asm(1):
Interpolated symbol "" does not exist
error: nested-bad-interpolation.asm(1):
syntax error, unexpected end of line
error: nested-bad-interpolation.asm(2):
Interpolated symbol "b" is a reserved keyword; add a '#' prefix to use it as a raw symbol
warning: nested-bad-interpolation.asm(2): [-Wobsolete]
Treating multi-unit strings as numbers is deprecated
error: nested-bad-interpolation.asm(3):
Interpolated symbol "c" is a reserved keyword; add a '#' prefix to use it as a raw symbol
error: nested-bad-interpolation.asm(3):
Interpolated symbol "" does not exist
warning: nested-bad-interpolation.asm(3): [-Wobsolete]
Treating multi-unit strings as numbers is deprecated
error: Assembly aborted (6 errors)!