throw an error if a character cannot be encoded

This commit is contained in:
Markus Triska
2020-07-23 00:35:23 +02:00
parent 4a90f13dee
commit 928c9c9aad

View File

@@ -5800,6 +5800,19 @@ impl MachineState {
} else { } else {
let mut bytes = vec![]; let mut bytes = vec![];
for c in self.heap_pstr_iter(self[temp_v!(1)]).to_string().chars() { 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); bytes.push(c as u8);
} }
let b64 = base64::encode_config(bytes, config); let b64 = base64::encode_config(bytes, config);