Avoid relying on sqlite to justify str::from_utf8_unchecked

This commit is contained in:
Thom Chiovoloni
2020-04-14 09:07:01 -07:00
committed by Thom Chiovoloni
parent 1b27ce0541
commit cf9b6e9ae2
4 changed files with 19 additions and 14 deletions

View File

@@ -69,9 +69,11 @@ impl Session<'_> {
let boxed_filter: *mut F = p_arg as *mut F;
let tbl_name = {
let c_slice = CStr::from_ptr(tbl_str).to_bytes();
str::from_utf8_unchecked(c_slice)
str::from_utf8(c_slice)
};
if let Ok(true) = catch_unwind(|| (*boxed_filter)(tbl_name)) {
if let Ok(true) =
catch_unwind(|| (*boxed_filter)(tbl_name.expect("non-utf8 table name")))
{
1
} else {
0
@@ -660,11 +662,11 @@ where
let tuple: *mut (Option<F>, C) = p_ctx as *mut (Option<F>, C);
let tbl_name = {
let c_slice = CStr::from_ptr(tbl_str).to_bytes();
str::from_utf8_unchecked(c_slice)
str::from_utf8(c_slice)
};
match *tuple {
(Some(ref filter), _) => {
if let Ok(true) = catch_unwind(|| filter(tbl_name)) {
if let Ok(true) = catch_unwind(|| filter(tbl_name.expect("illegal table name"))) {
1
} else {
0