Fix ValueRef::from_value

Handle text with internal nuls (#657)
This commit is contained in:
gwenn 2020-04-11 14:59:58 +02:00 committed by Thom Chiovoloni
parent 214986d232
commit 4dbfdc85fe

View File

@ -126,8 +126,6 @@ where
impl<'a> ValueRef<'a> {
pub(crate) unsafe fn from_value(value: *mut crate::ffi::sqlite3_value) -> ValueRef<'a> {
use crate::ffi;
use std::ffi::CStr;
use std::os::raw::c_char;
use std::slice::from_raw_parts;
match ffi::sqlite3_value_type(value) {
@ -136,13 +134,12 @@ impl<'a> ValueRef<'a> {
ffi::SQLITE_FLOAT => ValueRef::Real(ffi::sqlite3_value_double(value)),
ffi::SQLITE_TEXT => {
let text = ffi::sqlite3_value_text(value);
let len = ffi::sqlite3_value_bytes(value);
assert!(
!text.is_null(),
"unexpected SQLITE_TEXT value type with NULL data"
);
let s = CStr::from_ptr(text as *const c_char);
let s = s.to_bytes();
let s = from_raw_parts(text as *const u8, len as usize);
ValueRef::Text(s)
}
ffi::SQLITE_BLOB => {