diff options
-rw-r--r-- | src/lib.rs | 8 |
1 files 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<Context> { // 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 |