diff --git a/src/main.rs b/src/main.rs index 7948fca..be45de8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,26 +92,20 @@ fn get_lark_path() -> Option { }?; let v: std::io::Result = lark_cfg.get_raw_value("Lark Path"); let mut buf = v.unwrap(); - // Strip off NULL termination - buf.bytes.pop(); - buf.bytes.pop(); + + // Ensure the buffer is big enough. + if buf.bytes.len() <= 2 { + return None; + } + + // Sometimes it adds a NULL at the end. Strip off NULL termination. + if buf.bytes[buf.bytes.len()-2] == b'\0' { + buf.bytes.pop(); + buf.bytes.pop(); + } + let osstr = std::ffi::OsString::from_reg_value(&buf).unwrap(); Some(Path::new(&osstr).to_owned()) - // match v { - // Ok(v) => { - // print!("Values: "); - // use std::os::windows::ffi::OsStrExt; - // for (_idx, c) in v.encode_wide().enumerate() { - // print!(" {:04x}", c); - // } - // println!(); - - // let converted: PathBuf = v.into(); - // Some(converted.to_owned()) - // } - // Err(_) => None, - // } - // None } fn set_lark_path(new_path: &Path) -> std::io::Result<()> {