From 928c9c9aada4e7b0a3de4752d72f27d8aec63463 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Thu, 23 Jul 2020 00:35:23 +0200 Subject: [PATCH] throw an error if a character cannot be encoded --- src/machine/system_calls.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 7971583f..5a1f9d53 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -5800,6 +5800,19 @@ impl MachineState { } else { let mut bytes = vec![]; for c in self.heap_pstr_iter(self[temp_v!(1)]).to_string().chars() { + if c as u32 > 255 { + + let stub = MachineError::functor_stub(clause_name!("chars_base64"), 3); + + let err = MachineError::type_error( + self.heap.h(), + ValidType::Byte, + Addr::Char(c), + ); + + return Err(self.error_form(err, stub)); + } + bytes.push(c as u8); } let b64 = base64::encode_config(bytes, config); -- 2.54.0