1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-11 04:29:53 +00:00

proper error on unfinished hex escape at end of string. closes

This commit is contained in:
jespergravgaard 2021-12-19 00:24:13 +01:00
parent 1457a69098
commit 492e147441
4 changed files with 34 additions and 0 deletions
src
main/java/dk/camelot64/kickc/model/values
test

@ -173,7 +173,9 @@ public enum StringEncoding {
return '\\';
case 'x':
String hexNum = "";
if(escapedCharsIterator.isEmpty()) throw new CompileError("Unfinished string escape sequence at end of string");
hexNum += (char) escapedCharsIterator.pop().intValue();
if(escapedCharsIterator.isEmpty()) throw new CompileError("Unfinished string escape sequence at end of string");
hexNum += (char) escapedCharsIterator.pop().intValue();
final byte hexEncoding = (byte) Integer.parseInt(hexNum, 16);
return charFromEncoded(hexEncoding);

@ -1680,6 +1680,16 @@ public class TestProgramsFast extends TestPrograms {
compileAndCompare("code-after-return.c");
}
@Test
public void testStringEscapesErr3() throws IOException {
assertError("string-escapes-err-3.c", "Unfinished string escape sequence at end of string");
}
@Test
public void testStringEscapesErr2() throws IOException {
assertError("string-escapes-err-2.c", "Unfinished string escape sequence at end of string");
}
@Test
public void testStringEscapesErr1() throws IOException {
assertError("string-escapes-err-1.c", "Illegal string escape sequence");

@ -0,0 +1,11 @@
// Test errors using string escape sequences
// Half hex-escape
char MESSAGE[] = "qwe\xd";
char* SCREEN = (char*)0x0400;
void main() {
byte i=0;
while(MESSAGE[i])
SCREEN[i] = MESSAGE[i++];
}

@ -0,0 +1,11 @@
// Test errors using string escape sequences
// Half hex-escape
char MESSAGE[] = "qwe\x";
char* SCREEN = (char*)0x0400;
void main() {
byte i=0;
while(MESSAGE[i])
SCREEN[i] = MESSAGE[i++];
}