From e0e82e187767f163ddd27b888eff18f0b69343b8 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Wed, 18 Sep 2019 23:56:10 +0000 Subject: [PATCH] Fix ffi interoperability issue Clients expect empty "dbfile" argument to be treated as NULL value. This change fulfills their expectations. Closes: #530 --- deltachat-ffi/src/lib.rs | 2 +- src/context.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 593599b26..9db32d115 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -233,7 +233,7 @@ pub unsafe extern "C" fn dc_open( let ffi_context = &*context; let rust_cb = move |_ctx: &Context, evt: Event| ffi_context.translate_cb(evt); - let ctx = if blobdir.is_null() { + let ctx = if blobdir.is_null() || *blobdir == 0 { Context::new( Box::new(rust_cb), ffi_context.os_name.clone(), diff --git a/src/context.rs b/src/context.rs index 5217fc8e0..c118b70c4 100644 --- a/src/context.rs +++ b/src/context.rs @@ -475,6 +475,15 @@ mod tests { assert!(dbfile2.is_file()); } + #[test] + fn test_with_empty_blobdir() { + let tmp = tempfile::tempdir().unwrap(); + let dbfile = tmp.path().join("db.sqlite"); + let blobdir = PathBuf::new(); + let res = Context::with_blobdir(Box::new(|_, _| 0), "FakeOS".into(), dbfile, blobdir); + assert!(res.is_err()); + } + #[test] fn test_with_blobdir_not_exists() { let tmp = tempfile::tempdir().unwrap();