Skip to content

Commit

Permalink
Parser: don't concatenate improperly-encoded strings
Browse files Browse the repository at this point in the history
Fixes #674
  • Loading branch information
ehaas authored and Vexu committed Apr 8, 2024
1 parent 7757e64 commit 28ca8ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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" \

0 comments on commit 28ca8ca

Please sign in to comment.