diff options
| author | Raph Levien <raph@google.com> | 2017-02-22 09:30:46 -0800 |
|---|---|---|
| committer | Raph Levien <raph@google.com> | 2017-02-22 09:30:46 -0800 |
| commit | b3ee2490c2cba3f58476e520468afe0b828c0aa6 (patch) | |
| tree | 7f17f972f658ed00a7c310fd1448e9ab96eb07d9 /src/libstd | |
| parent | 81b9b3c542e0f3c3df799a9d66bb0120c7dbc44c (diff) | |
| parent | fc6f092c21a7a7249a9f8860f3cd10160aa36c02 (diff) | |
| download | rust-b3ee2490c2cba3f58476e520468afe0b828c0aa6.tar.gz rust-b3ee2490c2cba3f58476e520468afe0b828c0aa6.zip | |
Merge branch 'master' of https://github.com/rust-lang/rust into readdir
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 10 | ||||
| -rw-r--r-- | src/libstd/env.rs | 15 | ||||
| -rw-r--r-- | src/libstd/f32.rs | 2 | ||||
| -rw-r--r-- | src/libstd/f64.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/cursor.rs | 59 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 4 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 2 | ||||
| -rw-r--r-- | src/libstd/primitive_docs.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync/once.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 38 | ||||
| -rw-r--r-- | src/libstd/thread/local.rs | 4 |
11 files changed, 83 insertions, 57 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 079dbd667d6..fd5827b4c07 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -182,15 +182,15 @@ impl DefaultResizePolicy { // ---------------------- // To protect against degenerate performance scenarios (including DOS attacks), // the implementation includes an adaptive behavior that can resize the map -// early (before it's capacity is exceeded) when suspiciously long probe or -// foward shifts sequences are encounted. +// early (before its capacity is exceeded) when suspiciously long probe or +// forward shifts sequences are encountered. // // With this algorithm in place it would be possible to turn a CPU attack into -// a memory attack due to the agressive resizing. To prevent that the +// a memory attack due to the aggressive resizing. To prevent that the // adaptive behavior only triggers when the map occupancy is half the maximum occupancy. -// This reduces the effectivenes of the algorithm but also makes it completelly safe. +// This reduces the effectiveness of the algorithm but also makes it completely safe. // -// The previous safety measure that also prevents degenerate iteractions with +// The previous safety measure also prevents degenerate interactions with // really bad quality hash algorithms that can make normal inputs look like a // DOS attack. // diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 1ef2cb4ed15..dd4f1ff4f5e 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -96,7 +96,9 @@ pub struct VarsOs { inner: os_imp::Env } /// /// While iterating, the returned iterator will panic if any key or value in the /// environment is not valid unicode. If this is not desired, consider using the -/// `env::vars_os` function. +/// [`env::vars_os`] function. +/// +/// [`env::vars_os`]: fn.vars_os.html /// /// # Examples /// @@ -171,9 +173,12 @@ impl fmt::Debug for VarsOs { /// Fetches the environment variable `key` from the current process. /// -/// The returned result is `Ok(s)` if the environment variable is present and is +/// The returned result is [`Ok(s)`] if the environment variable is present and is /// valid unicode. If the environment variable is not present, or it is not -/// valid unicode, then `Err` will be returned. +/// valid unicode, then [`Err`] will be returned. +/// +/// [`Ok(s)`]: ../result/enum.Result.html#variant.Ok +/// [`Err`]: ../result/enum.Result.html#variant.Err /// /// # Examples /// @@ -199,7 +204,9 @@ fn _var(key: &OsStr) -> Result<String, VarError> { } /// Fetches the environment variable `key` from the current process, returning -/// `None` if the variable isn't set. +/// [`None`] if the variable isn't set. +/// +/// [`None`]: ../option/enum.Option.html#variant.None /// /// # Examples /// diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 7a676c041ad..544f4f9ddbe 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -264,7 +264,7 @@ impl f32 { /// /// assert!(abs_difference <= f32::EPSILON); /// ``` - /// [floating-point]: ../reference.html#machine-types + /// [floating-point]: ../reference/types.html#machine-types #[unstable(feature = "float_extras", reason = "signature is undecided", issue = "27752")] #[rustc_deprecated(since = "1.11.0", diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 67a1c302483..dd4bc253bed 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -206,7 +206,7 @@ impl f64 { /// /// assert!(abs_difference < 1e-10); /// ``` - /// [floating-point]: ../reference.html#machine-types + /// [floating-point]: ../reference/types.html#machine-types #[unstable(feature = "float_extras", reason = "signature is undecided", issue = "27752")] #[rustc_deprecated(since = "1.11.0", diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 0cff8661d88..60767ea4786 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -200,18 +200,20 @@ impl<T> Cursor<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T> io::Seek for Cursor<T> where T: AsRef<[u8]> { fn seek(&mut self, style: SeekFrom) -> io::Result<u64> { - let pos = match style { - SeekFrom::Start(n) => { self.pos = n; return Ok(n) } - SeekFrom::End(n) => self.inner.as_ref().len() as i64 + n, - SeekFrom::Current(n) => self.pos as i64 + n, + let (base_pos, offset) = match style { + SeekFrom::Start(n) => { self.pos = n; return Ok(n); } + SeekFrom::End(n) => (self.inner.as_ref().len() as u64, n), + SeekFrom::Current(n) => (self.pos, n), }; - - if pos < 0 { - Err(Error::new(ErrorKind::InvalidInput, - "invalid seek to a negative position")) + let new_pos = if offset >= 0 { + base_pos.checked_add(offset as u64) } else { - self.pos = pos as u64; - Ok(self.pos) + base_pos.checked_sub((offset.wrapping_neg()) as u64) + }; + match new_pos { + Some(n) => {self.pos = n; Ok(self.pos)} + None => Err(Error::new(ErrorKind::InvalidInput, + "invalid seek to a negative or overflowing position")) } } } @@ -527,6 +529,43 @@ mod tests { } #[test] + fn seek_past_i64() { + let buf = [0xff]; + let mut r = Cursor::new(&buf[..]); + assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6); + assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6); + assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006); + assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006); + assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err()); + assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6); + + let mut r = Cursor::new(vec![10]); + assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6); + assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6); + assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006); + assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006); + assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err()); + assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6); + + let mut buf = [0]; + let mut r = Cursor::new(&mut buf[..]); + assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6); + assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6); + assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006); + assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006); + assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err()); + assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6); + + let mut r = Cursor::new(vec![10].into_boxed_slice()); + assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6); + assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6); + assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006); + assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006); + assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err()); + assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6); + } + + #[test] fn seek_before_0() { let buf = [0xff]; let mut r = Cursor::new(&buf[..]); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 88c2310a86e..070690773b6 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -189,8 +189,8 @@ //! [`sync`]: sync/index.html //! [`thread`]: thread/index.html //! [`use std::env`]: env/index.html -//! [`use`]: ../book/crates-and-modules.html#Importing%20Modules%20with%20use -//! [crate root]: ../book/crates-and-modules.html#Basic%20terminology%3A%20Crates%20and%20Modules +//! [`use`]: ../book/crates-and-modules.html#importing-modules-with-use +//! [crate root]: ../book/crates-and-modules.html#basic-terminology-crates-and-modules //! [crates.io]: https://crates.io //! [deref coercions]: ../book/deref-coercions.html //! [files]: fs/struct.File.html diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index d79a9a202d9..a1f092621cb 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -441,7 +441,7 @@ pub mod builtin { /// leads to less duplicated code. /// /// The syntax given to this macro is the same syntax as [the `cfg` - /// attribute](../reference.html#conditional-compilation). + /// attribute](../book/conditional-compilation.html). /// /// # Examples /// diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index 1b3e17c300e..11197db98a3 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -490,7 +490,7 @@ mod prim_str { } /// assert_eq!(tuple.2, 'c'); /// ``` /// -/// For more about tuples, see [the book](../book/primitive-types.html#Tuples). +/// For more about tuples, see [the book](../book/primitive-types.html#tuples). /// /// # Trait implementations /// diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index ba993751391..1e7394c0b09 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -316,7 +316,7 @@ impl Once { } // Once we've enqueued ourselves, wait in a loop. - // Aftewards reload the state and continue with what we + // Afterwards reload the state and continue with what we // were doing from before. while !node.signaled.load(Ordering::SeqCst) { thread::park(); diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 6dc85840a63..36928696c40 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -483,41 +483,21 @@ pub fn home_dir() -> Option<PathBuf> { target_os = "nacl", target_os = "emscripten")))] unsafe fn fallback() -> Option<OsString> { - #[cfg(not(target_os = "solaris"))] - unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, - buf: &mut Vec<c_char>) -> Option<()> { - let mut result = ptr::null_mut(); - match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), - buf.capacity(), - &mut result) { - 0 if !result.is_null() => Some(()), - _ => None - } - } - - #[cfg(target_os = "solaris")] - unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, - buf: &mut Vec<c_char>) -> Option<()> { - // getpwuid_r semantics is different on Illumos/Solaris: - // http://illumos.org/man/3c/getpwuid_r - let result = libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), - buf.capacity()); - if result.is_null() { None } else { Some(()) } - } - let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, n => n as usize, }; let mut buf = Vec::with_capacity(amt); let mut passwd: libc::passwd = mem::zeroed(); - - if getpwduid_r(libc::getuid(), &mut passwd, &mut buf).is_some() { - let ptr = passwd.pw_dir as *const _; - let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); - Some(OsStringExt::from_vec(bytes)) - } else { - None + let mut result = ptr::null_mut(); + match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(), + buf.capacity(), &mut result) { + 0 if !result.is_null() => { + let ptr = passwd.pw_dir as *const _; + let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); + Some(OsStringExt::from_vec(bytes)) + }, + _ => None, } } } diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 5166ddf8a21..66f09a7069c 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -28,8 +28,8 @@ use mem; /// # Initialization and Destruction /// /// Initialization is dynamically performed on the first call to `with()` -/// within a thread, and values support destructors which will be run when a -/// thread exits. +/// within a thread, and values that implement `Drop` get destructed when a +/// thread exits. Some caveats apply, which are explained below. /// /// # Examples /// |
