Fix bugs (#93)

* fix(repl): pass null pointer instead of empty string

* fix(peerstate): ensure load and store to the db works
This commit is contained in:
Friedel Ziegelmayer
2019-05-28 17:59:41 +02:00
committed by Lars-Magnus Skog
parent 0d51c7dd2e
commit d033667433
9 changed files with 269 additions and 142 deletions

View File

@@ -99,21 +99,17 @@ impl Key {
match res {
Ok(key) => Some(key),
Err(err) => {
eprintln!("Invalid key bytes: {:?}\n{}", err, hex::encode(bytes));
eprintln!("Invalid key bytes: {:?}", err);
None
}
}
}
pub fn from_binary(
data: *const libc::c_void,
len: libc::c_int,
key_type: KeyType,
) -> Option<Self> {
pub fn from_binary(data: *const u8, len: libc::c_int, key_type: KeyType) -> Option<Self> {
assert!(!data.is_null(), "missing data");
assert!(len > 0);
let bytes = unsafe { slice::from_raw_parts(data as *const u8, len as usize) };
let bytes = unsafe { slice::from_raw_parts(data, len as usize) };
Self::from_slice(bytes, key_type)
}
@@ -124,9 +120,7 @@ impl Key {
) -> Option<Self> {
assert!(!stmt.is_null(), "missing statement");
let data = unsafe {
sqlite3_column_blob(stmt, index) as *mut libc::c_uchar as *const libc::c_void
};
let data = unsafe { sqlite3_column_blob(stmt, index) as *const u8 };
let len = unsafe { sqlite3_column_bytes(stmt, index) };
Self::from_binary(data, len, key_type)