tsc: do safe utf-8 conversion

Fixes crash on Windows
This commit is contained in:
Alula 2020-08-28 21:57:37 +02:00
parent ff1dca747c
commit fd0fe7c400
No known key found for this signature in database
GPG Key ID: 3E00485503A1D8BA
1 changed files with 3 additions and 4 deletions

View File

@ -746,8 +746,7 @@ impl TextScript {
/// Compiles a decrypted text script data into internal bytecode. /// Compiles a decrypted text script data into internal bytecode.
pub fn compile(data: &[u8], strict: bool) -> GameResult<TextScript> { pub fn compile(data: &[u8], strict: bool) -> GameResult<TextScript> {
let code = unsafe { std::str::from_utf8_unchecked(data) }; println!("data: {}", String::from_utf8_lossy(data));
println!("data: {}", code);
let mut event_map = HashMap::new(); let mut event_map = HashMap::new();
let mut iter = data.iter().copied().peekable(); let mut iter = data.iter().copied().peekable();
@ -813,9 +812,9 @@ impl TextScript {
.map(|t| [t.0, t.1, t.2]) .map(|t| [t.0, t.1, t.2])
.ok_or_else(|| ParseError(str!("Script unexpectedly ended.")))?; .ok_or_else(|| ParseError(str!("Script unexpectedly ended.")))?;
let code = unsafe { std::str::from_utf8_unchecked(&n) }; let code = String::from_utf8_lossy(&n);
TextScript::compile_code(code, strict, iter, &mut bytecode)?; TextScript::compile_code(code.as_ref(), strict, iter, &mut bytecode)?;
} }
_ => { _ => {
char_buf.push(chr); char_buf.push(chr);