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

Parser: don't concatenate improperly-encoded strings #676

Merged
merged 1 commit into from
Apr 8, 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
11 changes: 9 additions & 2 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7995,7 +7995,8 @@ fn stringLiteral(p: *Parser) Error!Result {
return error.ParsingFailed;
}
}
assert(string_end > p.tok_i);
const count = string_end - p.tok_i;
assert(count > 0);

const char_width = string_kind.charUnitSize(p.comp);

Expand Down Expand Up @@ -8041,7 +8042,13 @@ fn stringLiteral(p: *Parser) Error!Result {
},
}
},
.improperly_encoded => |bytes| p.strings.appendSliceAssumeCapacity(bytes),
.improperly_encoded => |bytes| {
if (count > 1) {
try p.errTok(.illegal_char_encoding_error, p.tok_i);
return error.ParsingFailed;
}
p.strings.appendSliceAssumeCapacity(bytes);
},
.utf8_text => |view| {
switch (char_width) {
.@"1" => p.strings.appendSliceAssumeCapacity(view.bytes),
Expand Down
5 changes: 5 additions & 0 deletions test/cases/concat improperly encoded strings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Note: saved with iso-8859-1 encoding, do not change */
int *p = L"" "ÿ";

#define EXPECTED_ERRORS "concat improperly encoded strings.c:2:14: error: illegal character encoding in character literal" \

Loading