From e975211a294771dd23f65353394010d8bd382020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Thu, 20 Aug 2020 16:00:22 +0200 Subject: [PATCH] rust: even safer casting to char --- rust/src/cells.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rust/src/cells.rs b/rust/src/cells.rs index 520755401..d78cdaadb 100644 --- a/rust/src/cells.rs +++ b/rust/src/cells.rs @@ -262,9 +262,14 @@ pub fn cell_wide_left_p(cell: &cell) -> bool { // TODO: TEST #[inline] pub fn cell_strdup(plane: &ncplane, cell: &cell) -> EGC { - unsafe { - core::char::from_u32_unchecked(libc::strdup(ffi::cell_extended_gcluster(plane, cell)) as i32 as u32) - } + core::char::from_u32( + unsafe {libc::strdup(ffi::cell_extended_gcluster(plane, cell)) } as i32 as u32) + .expect("wrong char") + + // unsafer option B (maybe faster, TODO: bench) + // unsafe { + // core::char::from_u32_unchecked(libc::strdup(ffi::cell_extended_gcluster(plane, cell)) as i32 as u32) + // } } /// Extract the three elements of a cell.