diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index 21245e09..67b21739 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -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); @@ -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), diff --git a/test/cases/concat improperly encoded strings.c b/test/cases/concat improperly encoded strings.c new file mode 100644 index 00000000..9d5c53a0 --- /dev/null +++ b/test/cases/concat improperly encoded strings.c @@ -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" \ +