From 6dd8cc2dc4569766d573c21afa71632b7c8d0d96 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 31 Mar 2018 15:12:56 -0300 Subject: [PATCH] Fix find_context --- src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 45b3c66..0bc0f6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -635,10 +635,12 @@ impl<'a> EnsureValidContext<'a> { pub fn find_context(&mut self, servname: Option<&str>, channel: Option<&str>) -> Option { // this was a mistake but oh well let ph = self.ph.ph; - let servname = CString::new(servname).unwrap(); - let channel = CString::new(channel).unwrap(); + let servname = servname.map(|x| CString::new(x).unwrap()); + let channel = channel.map(|x| CString::new(x).unwrap()); let ctx = unsafe { - ((*ph).hexchat_find_context)(ph, servname.as_ptr(), channel.as_ptr()) + let sptr = servname.map(|x| x.as_ptr()).unwrap_or(ptr::null()); + let cptr = channel.map(|x| x.as_ptr()).unwrap_or(ptr::null()); + ((*ph).hexchat_find_context)(ph, sptr, cptr) }; if ctx.is_null() { None