From 4dbfdc85fe8e8cad161c1c8bcc44ea05610cac52 Mon Sep 17 00:00:00 2001 From: gwenn Date: Sat, 11 Apr 2020 14:59:58 +0200 Subject: [PATCH] Fix ValueRef::from_value Handle text with internal nuls (#657) --- src/types/value_ref.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/types/value_ref.rs b/src/types/value_ref.rs index 503f905..80d2457 100644 --- a/src/types/value_ref.rs +++ b/src/types/value_ref.rs @@ -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 => {