diff options
| author | Adolfo OchagavĂa <aochagavia92@gmail.com> | 2014-07-22 18:24:33 +0200 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-24 07:25:48 -0700 |
| commit | 4ea1dd54943bb208d585c7ae8138df5699995a77 (patch) | |
| tree | 072829598fe36318152b41565c6bd95312277627 /src/libnative/io | |
| parent | 6988bcd74c6ab85d0a5f85c8b96c61f7fb75ad1d (diff) | |
| download | rust-4ea1dd54943bb208d585c7ae8138df5699995a77.tar.gz rust-4ea1dd54943bb208d585c7ae8138df5699995a77.zip | |
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]
Diffstat (limited to 'src/libnative/io')
| -rw-r--r-- | src/libnative/io/addrinfo.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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() |
