From 2fb6cc6f4d2e6ea662c781b65bcafff3221461e1 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Thu, 6 Jun 2019 08:16:26 +0200 Subject: [PATCH] handle null args --- ports/libsimpleservo/capi/src/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ports/libsimpleservo/capi/src/lib.rs b/ports/libsimpleservo/capi/src/lib.rs index 50af7a4d2846..b080218492d7 100644 --- a/ports/libsimpleservo/capi/src/lib.rs +++ b/ports/libsimpleservo/capi/src/lib.rs @@ -75,13 +75,16 @@ fn init( ) { crate::env_logger::init(); - let args = unsafe { CStr::from_ptr(opts.args) }; - let args = args - .to_str() - .unwrap_or("") - .split(' ') - .map(|s| s.to_owned()) - .collect(); + let args = if !opts.args.is_null() { + let args = unsafe { CStr::from_ptr(opts.args) }; + args.to_str() + .unwrap_or("") + .split(' ') + .map(|s| s.to_owned()) + .collect() + } else { + vec![] + }; let url = unsafe { CStr::from_ptr(opts.url) }; let url = url.to_str().map(|s| s.to_string()).ok();