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 #729
This commit is contained in:
parent
1457a69098
commit
492e147441
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");
|
||||
|
11
src/test/kc/string-escapes-err-2.c
Normal file
11
src/test/kc/string-escapes-err-2.c
Normal file
@ -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++];
|
||||
}
|
11
src/test/kc/string-escapes-err-3.c
Normal file
11
src/test/kc/string-escapes-err-3.c
Normal file
@ -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++];
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user