From 4ea1dd54943bb208d585c7ae8138df5699995a77 Mon Sep 17 00:00:00 2001 From: Adolfo OchagavĂ­a Date: Tue, 22 Jul 2014 18:24:33 +0200 Subject: Add a null pointer check to CString::new This also removes checks in other methods of `CString` Breaking changes: * `CString::new` now fails if `buf` is null. To avoid this add a check before creatng a new `CString` . * The `is_null` and `is_not_null` methods are deprecated, because a `CString` cannot be null. * Other methods which used to fail if the `CString` was null do not fail anymore [breaking-change] --- src/libnative/io/addrinfo.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libnative') diff --git a/src/libnative/io/addrinfo.rs b/src/libnative/io/addrinfo.rs index 0977b55d8b9..343fe05ed42 100644 --- a/src/libnative/io/addrinfo.rs +++ b/src/libnative/io/addrinfo.rs @@ -10,7 +10,6 @@ use libc::{c_char, c_int}; use libc; -use std::c_str::CString; use std::mem; use std::ptr::{null, mut_null}; use std::rt::rtio; @@ -27,8 +26,8 @@ impl GetAddrInfoRequest { { assert!(host.is_some() || servname.is_some()); - let c_host = host.map_or(unsafe { CString::new(null(), true) }, |x| x.to_c_str()); - let c_serv = servname.map_or(unsafe { CString::new(null(), true) }, |x| x.to_c_str()); + let c_host = host.map(|x| x.to_c_str()); + let c_serv = servname.map(|x| x.to_c_str()); let hint = hint.map(|hint| { libc::addrinfo { @@ -50,8 +49,8 @@ impl GetAddrInfoRequest { // Make the call let s = unsafe { - let ch = if c_host.is_null() { null() } else { c_host.as_ptr() }; - let cs = if c_serv.is_null() { null() } else { c_serv.as_ptr() }; + let ch = if c_host.is_none() { null() } else { c_host.unwrap().as_ptr() }; + let cs = if c_serv.is_none() { null() } else { c_serv.unwrap().as_ptr() }; getaddrinfo(ch, cs, hint_ptr, &mut res) }; @@ -104,6 +103,7 @@ fn get_error(_: c_int) -> IoError { #[cfg(not(windows))] fn get_error(s: c_int) -> IoError { + use std::c_str::CString; let err_str = unsafe { CString::new(gai_strerror(s), false).as_str().unwrap().to_string() -- cgit 1.4.1-3-g733a5