diff --git a/src/cursor.rs b/src/cursor.rs index 7bc8ce4..aa26746 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -290,7 +290,6 @@ mod test { use flags::*; use super::*; use test_utils::*; - use transaction::*; #[test] fn test_get() { diff --git a/src/environment.rs b/src/environment.rs index a2ebdcc..5962f3a 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -1,5 +1,5 @@ use libc::{c_uint, size_t}; -use std::ffi::CString; +use std::ffi::{CString, NulError}; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; #[cfg(windows)] @@ -207,10 +207,11 @@ impl EnvironmentBuilder { lmdb_try_with_cleanup!(ffi::mdb_env_set_mapsize(env, map_size), ffi::mdb_env_close(env)) } - lmdb_try_with_cleanup!(ffi::mdb_env_open(env, - CString::new(path.as_os_str().as_bytes()).unwrap().as_ptr(), - self.flags.bits(), - mode), + let path = match CString::new(path.as_os_str().as_bytes()) { + Ok(path) => path, + Err(NulError { .. }) => return Err(::Error::Invalid), + }; + lmdb_try_with_cleanup!(ffi::mdb_env_open(env, path.as_ptr(), self.flags.bits(), mode), ffi::mdb_env_close(env)); } Ok(Environment { env: env, dbi_open_mutex: Mutex::new(()) }) diff --git a/src/error.rs b/src/error.rs index 5f73391..7907c40 100644 --- a/src/error.rs +++ b/src/error.rs @@ -145,5 +145,4 @@ mod test { assert_eq!("MDB_NOTFOUND: No matching key/data pair found", Error::NotFound.description()); } - }