compiles but crashes

master
Lukáš Hozda 4 years ago
parent aafde299a5
commit 0b0024ebac

@ -498,10 +498,10 @@ pub unsafe extern "C" fn dial(
);
hints.ai_family = 0 as libc::c_int;
hints.ai_socktype = SOCK_STREAM as libc::c_int;
if getaddrinfo(host, port, &mut hints, &mut res) != 0 as libc::c_int {
if getaddrinfo(CString::new(host).unwrap().into_raw(), port, &mut hints, &mut res) != 0 as libc::c_int {
eprintln!(
"error: cannot resolve hostname '{}:{}': {}",
CStr::from_ptr(host).to_str().unwrap(),
host,
CStr::from_ptr(port).to_str().unwrap(),
CStr::from_ptr(strerror(*__errno_location())).to_str().unwrap()
);
@ -579,7 +579,7 @@ pub unsafe extern "C" fn read_line(
return 1 as libc::c_int;
}
pub unsafe extern "C" fn download_file(
mut host: *const libc::c_char,
mut host: &str,
mut port: *const libc::c_char,
mut selector: *const libc::c_char,
mut fd: libc::c_int,
@ -594,7 +594,7 @@ pub unsafe extern "C" fn download_file(
selector,
);
}
srvfd = dial(host, port, selector);
srvfd = dial(&host, port, selector);
if srvfd == -(1 as libc::c_int) {
printf(
b"\x1b[2Kerror: downloading [%s] failed\n\x00" as *const u8
@ -634,7 +634,7 @@ pub unsafe extern "C" fn download_file(
return 1 as libc::c_int;
}
pub unsafe extern "C" fn download_temp(
mut host: *const libc::c_char,
mut host: &str,
mut port: *const libc::c_char,
mut selector: *const libc::c_char,
) -> libc::c_int {
@ -831,7 +831,7 @@ pub unsafe extern "C" fn is_valid_directory_entry(
};
}
pub unsafe extern "C" fn view_directory(
mut host: String,
mut host: &str,
mut port: *const libc::c_char,
mut selector: *const libc::c_char,
mut make_current: libc::c_int,
@ -842,7 +842,7 @@ pub unsafe extern "C" fn view_directory(
let mut head_read: libc::c_int = 0;
let mut line: [libc::c_char; 1024] = [0; 1024];
let mut head: [[libc::c_char; 1024]; 5] = [[0; 1024]; 5];
srvfd = dial(host, port, selector);
srvfd = dial(&host, port, selector);
if srvfd != -(1 as libc::c_int) {
/* only adapt current prompt when successful */
/* make history entry */
@ -850,7 +850,7 @@ pub unsafe extern "C" fn view_directory(
add_history();
}
/* don't overwrite the current_* things... */
if host != current_host.as_mut_ptr() as *const libc::c_char {
if host != CString::new(current_host.iter().take_while(|x| **x != 0).map(|x| *x as u8).collect::<Vec<_>>()).unwrap().into_string().unwrap() {
snprintf(
current_host.as_mut_ptr(),
mem::size_of::<[libc::c_char; 512]>() as libc::c_ulong,
@ -1145,7 +1145,7 @@ pub unsafe extern "C" fn view_history(mut key: libc::c_int) {
while let Some(l) = link {
if history_key == key {
view_directory(
(*l).host,
&(*l).host,
(*l).port,
(*l).selector,
0 as libc::c_int,
@ -1196,7 +1196,7 @@ pub unsafe extern "C" fn view_bookmarks(mut key: libc::c_int) {
) != 0
{
view_directory(
CString::from_raw(parsed_host).into_string().unwrap(),
&CString::new(parsed_host.iter().take_while(|x| **x != 0).map(|x| *x as u8).collect::<Vec<_>>()).unwrap().into_string().unwrap(),
parsed_port.as_mut_ptr(),
parsed_selector.as_mut_ptr(),
0 as libc::c_int,
@ -1221,7 +1221,7 @@ pub fn pop_history() {
Some(h) => {
/* reload page from history (and don't count as history) */
unsafe { view_directory(
(*h).host,
&(*h).host,
(*h).port,
(*h).selector,
0 as libc::c_int,
@ -1244,34 +1244,34 @@ pub unsafe extern "C" fn follow_link(mut key: libc::c_int) -> libc::c_int {
CString::new(config.cmd_text.clone())
.unwrap()
.into_raw(),
(*l).host,
&(*l).host,
(*l).port,
(*l).selector,
);
}
'1' => {
view_directory(
(*l).host,
&(*l).host,
(*l).port,
(*l).selector,
1 as libc::c_int,
);
}
'7' => {
view_search((*l).host, (*l).port, (*l).selector);
view_search(&(*l).host, (*l).port, (*l).selector);
}
'5' | '9' => {
view_download((*l).host, (*l).port, (*l).selector);
view_download(&(*l).host, (*l).port, (*l).selector);
}
'8' => {
view_telnet((*l).host, (*l).port);
view_telnet(&(*l).host, (*l).port);
}
'f' | 'I' | 'p' => {
view_file(
CString::new(config.cmd_image.clone())
.unwrap()
.into_raw(),
(*l).host,
&(*l).host,
(*l).port,
(*l).selector,
);
@ -1281,7 +1281,7 @@ pub unsafe extern "C" fn follow_link(mut key: libc::c_int) -> libc::c_int {
CString::new(config.cmd_browser.clone())
.unwrap()
.into_raw(),
(*l).host,
&(*l).host,
(*l).port,
(*l).selector,
);
@ -1291,7 +1291,7 @@ pub unsafe extern "C" fn follow_link(mut key: libc::c_int) -> libc::c_int {
CString::new(config.cmd_player.clone())
.unwrap()
.into_raw(),
(*l).host,
&(*l).host,
(*l).port,
(*l).selector,
);
@ -1315,7 +1315,7 @@ pub unsafe extern "C" fn download_link(mut key: libc::c_int) {
if (*l).key as libc::c_int != key {
link = (*l).next
} else {
view_download((*l).host, (*l).port, (*l).selector);
view_download(&(*l).host, (*l).port, (*l).selector);
return;
}
}
@ -1443,7 +1443,7 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
}
/* main loop */
view_directory(
parsed_host.as_mut_ptr(),
&CString::new(parsed_host.iter().take_while(|x| **x != 0).map(|x| *x as u8).collect::<Vec<_>>()).unwrap().into_string().unwrap(),
parsed_port.as_mut_ptr(),
parsed_selector.as_mut_ptr(),
0 as libc::c_int,
@ -1476,7 +1476,7 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
}
42 => {
view_directory(
current_host.as_mut_ptr(),
&CString::new(current_host.iter().take_while(|x| **x != 0).map(|x| *x as u8).collect::<Vec<_>>()).unwrap().into_string().unwrap(),
current_port.as_mut_ptr(),
current_selector.as_mut_ptr(),
0 as libc::c_int,
@ -1504,7 +1504,7 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
!= 0
{
view_directory(
parsed_host.as_mut_ptr(),
&CString::new(parsed_host.iter().take_while(|x| **x != 0).map(|x| *x as u8).collect::<Vec<_>>()).unwrap().into_string().unwrap(),
parsed_port.as_mut_ptr(),
parsed_selector.as_mut_ptr(),
1 as libc::c_int,

Loading…
Cancel
Save