summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2018-09-20std: Check for overflow in `str::repeat`Alex Crichton-1/+28
This commit fixes a buffer overflow issue in the standard library discovered by Scott McMurray where if a large number was passed to `str::repeat` it may cause and out of bounds write to the buffer of a `Vec`. This bug was accidentally introduced in #48657 when optimizing the `str::repeat` function. The bug affects stable Rust releases 1.26.0 to 1.29.0. We plan on backporting this fix to create a 1.29.1 release, and the 1.30.0 release onwards will include this fix. The fix in this commit is to introduce a deterministic panic in the case of capacity overflow. When repeating a slice where the resulting length is larger than the address space, there’s no way it can succeed anyway! The standard library and surrounding libraries were briefly checked to see if there were othere instances of preallocating a vector with a calculation that may overflow. No instances of this bug (out of bounds write due to a calculation overflow) were found at this time. Note that this commit is the first steps towards fixing this issue, we'll be making a formal post to the Rust security list once these commits have been merged.
2018-07-28Rollup merge of #52769 - sinkuu:stray_test, r=alexcrichtonkennytm-19/+12
Incorporate a stray test `liballoc/repeat-generic-slice.rs` doesn't seem to be tested (I think it was intended to be placed in `run-pass`). This PR incorporates the test into `liballoc/tests`.
2018-07-27Auto merge of #52336 - ishitatsuyuki:dyn-rollup, r=Mark-Simulacrumbors-9/+8
Rollup of bare_trait_objects PRs All deny attributes were moved into bootstrap so they can be disabled with a line of config. Warnings for external tools are allowed and it's up to the tool's maintainer to keep it warnings free. r? @Mark-Simulacrum cc @ljedrz @kennytm
2018-07-27Incorporate a stray testShotaro Yamada-19/+12
2018-07-25Deny bare_trait_objects globallyTatsuyuki Ishi-1/+0
2018-07-25Add missing dynTatsuyuki Ishi-8/+8
2018-07-24Impl Executor for Box<E: Executor>tinaun-1/+14
2018-07-24Auto merge of #52189 - cuviper:static-box-leak, r=blussbors-1/+3
doc: Clarify the lifetime returned by `Box::leak` `Box::leak` mentions that it can return a `'static` reference, but it wasn't immediately clear to me why it doesn't always do so. This is because of the `T: 'a` constraint needed to form a valid reference, and in general we want to be more flexible than requiring `T: 'static`. This patch tries to clarify the relationship between `T` and `'a`.
2018-07-23typosRalf Jung-4/+4
2018-07-23Don't use NonNull::dangling as sentinel valueRalf Jung-9/+17
Instead, rely on alignment and use usize::MAX as sentinel.
2018-07-22Rollup merge of #51807 - newpavlov:deprecate_str_slice, r=alexcrichtonkennytm-9/+9
Deprecation of str::slice_unchecked(_mut) Closes #51715 I am not sure if 1.28.0 or 1.29.0 should be used for deprecation version, for now it's 1.28.0. Additionally I've replaced `slice_unchecked` uses with `get_unchecked`. The only places where this method is still used are `src/liballoc/tests/str.rs` and `src/liballoc/tests/str.rs`.
2018-07-20data_structures: Add a reference wrapper for pointer-indexed maps/setsVadim Petrochenkov-1/+1
Use `ptr::eq` for comparing pointers
2018-07-18Rollup merge of #52116 - Pazzaz:match-str-case, r=SimonSapinkennytm-2/+27
Handle array manually in str case conversion methods Avoiding the overhead incurred from `String.extend(char.to_lowercase())` showed a notable performance improvement when I benchmarked it. I tested on these strings: ```rust ALL_LOWER: "loremipsumdolorsitametduosensibusmnesarchumabcdefgh" ALL_UPPER: "LOREMIPSUMDOLORSITAMETDUOSENSIBUSMNESARCHUMABCDEFGH" REALISTIC_UPPER: "LOREM IPSUM DOLOR SIT AMET, DUO SENSIBUS MNESARCHUM" SIGMAS: "ΣΣΣΣΣ ΣΣΣΣΣ ΣΣΣΣΣ ΣΣΣ ΣΣΣΣ, ΣΣΣ ΣΣΣΣΣΣΣΣ ΣΣΣΣΣΣΣΣΣΣ" WORD_UPPER: "Lorem Ipsum Dolor Sit Amet, Duo Sensibus Mnesarchum" ``` the performance improvements of `to_lowercase()` were ``` running 10 tests test tests::all_lower ... bench: 1,752 ns/iter (+/- 49) test tests::all_lower_new ... bench: 1,266 ns/iter (+/- 15) -28% test tests::all_upper ... bench: 1,832 ns/iter (+/- 39) test tests::all_upper_new ... bench: 1,337 ns/iter (+/- 18) -27% test tests::realistic_upper ... bench: 1,993 ns/iter (+/- 14) test tests::realistic_upper_new ... bench: 1,445 ns/iter (+/- 22) -27% test tests::sigmas ... bench: 1,342 ns/iter (+/- 39) test tests::sigmas_new ... bench: 1,226 ns/iter (+/- 16) -9% test tests::word_upper ... bench: 1,899 ns/iter (+/- 12) test tests::word_upper_new ... bench: 1,381 ns/iter (+/- 26) -27% ``` and of `to_uppercase()` ``` running 10 tests test tests::all_lower ... bench: 1,813 ns/iter (+/- 20) test tests::all_lower_new ... bench: 1,321 ns/iter (+/- 16) -27% test tests::all_upper ... bench: 1,629 ns/iter (+/- 22) test tests::all_upper_new ... bench: 1,241 ns/iter (+/- 9) -24% test tests::realistic_upper ... bench: 1,670 ns/iter (+/- 24) test tests::realistic_upper_new ... bench: 1,241 ns/iter (+/- 17) -26% test tests::sigmas ... bench: 2,053 ns/iter (+/- 20) test tests::sigmas_new ... bench: 1,753 ns/iter (+/- 23) -15% test tests::word_upper ... bench: 1,873 ns/iter (+/- 30) test tests::word_upper_new ... bench: 1,412 ns/iter (+/- 25) -25% ``` I gave up on the more advanced method from #52061 as it wasn't always a clear improvement and would help in even less cases if this PR was merged.
2018-07-11Revert borked changes in last commit.ljedrz-14/+15
2018-07-10Add missing dyn in liballocljedrz-37/+36
2018-07-10Deny bare trait objects in in src/liballocljedrz-12/+13
2018-07-09doc: Clarify the lifetime returned by `Box::leak`Josh Stone-1/+3
`Box::leak` mentions that it can return a `'static` reference, but it wasn't immediately clear to me why it doesn't always do so. This is because of the `T: 'a` constraint needed to form a valid reference, and in general we want to be more flexible than requiring `T: 'static`. This patch tries to clarify the relationship between `T` and `'a`.
2018-07-09Auto merge of #52159 - SimonSapin:alloc-prelude, r=alexcrichtonbors-1/+30
Add the `alloc::prelude` module It contains the re-exports that are in `std::prelude::v1` but not in `core::prelude::v1`. Calling it prelude is somewhat of a misnomer since (unlike those modules in `std` or `core`) its contents are never implicitly imported in modules. Rather it is intended to be used with an explicit glob import like `use alloc::prelude::*;`. However there is precedent for the same misnomer with `std::io::prelude`, for example. This new module is unstable with the same feature name as the `alloc` care. They are proposed for stabilization together in RFC https://github.com/rust-lang/rfcs/pull/2480.
2018-07-09Removed a single trailing space. Oops.Orson Peters-1/+1
2018-07-09Reimplemented Vec's swap_remove to not rely on pop.Orson Peters-4/+6
2018-07-09Performance improvement of Vec's swap_remove.Orson Peters-3/+7
2018-07-07Add the `alloc::prelude` moduleSimon Sapin-1/+30
It contains the re-exports that are in `std::prelude::v1` but not in `core::prelude::v1`. Calling it prelude is somewhat of a misnomer since (unlike those modules in `std` or `core`) its contents are never implicitly imported in modules. Rather it is intended to be used with an explicit glob import like `use alloc::prelude::*;`. However there is precedent for the same misnomer with `std::io::prelude`, for example. This new module is unstable with the same feature name as the `alloc` care. They are proposed for stabilization together in RFC https://github.com/rust-lang/rfcs/pull/2480
2018-07-06Rollup merge of #52103 - tmccombs:rc_downcast, r=Mark-SimulacrumMark Rousskov-4/+2
Stabilize rc_downcast Fixes #44608
2018-07-07Fix is_dangling import when Arc is #[cfg]’ed outSimon Sapin-7/+7
2018-07-07Add some unit tests for dangling Weak referencesSimon Sapin-0/+112
2018-07-07Rc: remove unused allocation from Weak::new()Simon Sapin-24/+37
Same as https://github.com/rust-lang/rust/pull/50357
2018-07-07Use an aligned dangling pointer in Weak::new, rather than address 1Simon Sapin-21/+29
2018-07-06Handle array manually in string case conversion methodsPazzaz-2/+27
2018-07-06Auto merge of #51953 - japaric:atomic-load-store, r=alexcrichtonbors-4/+16
enable Atomic*.{load,store} for ARMv6-M / MSP430 closes #45085 as proposed in https://github.com/rust-lang/rust/issues/45085#issuecomment-384825434 this commit adds an `atomic_cas` target option and extends the `#[cfg(target_has_atomic)]` attribute to enable a subset of the `Atomic*` API on architectures that don't support atomic CAS natively, like MSP430 and ARMv6-M. r? @alexcrichton
2018-07-06Stabilize rc_downcastThayne McCombs-4/+2
Fixes #44608
2018-07-05#[cfg(target_has_atomic_cas)] -> #[cfg(target_has_atomic = "cas")]Jorge Aparicio-9/+16
2018-07-05enable Atomic*.{load,store} for ARMv6-M / MSP430Jorge Aparicio-4/+9
closes #45085 this commit adds an `atomic_cas` target option and an unstable `#[cfg(target_has_atomic_cas)]` attribute to enable a subset of the `Atomic*` API on architectures that don't support atomic CAS natively, like MSP430 and ARMv6-M.
2018-07-03Strenghten synchronization in `Arc::is_unique`Ralf Jung-6/+7
Previously, `is_unique` would not synchronize at all with a `drop` that returned early because it was not the last reference, leading to a data race. Fixes #51780
2018-07-03Rollup merge of #51914 - ↵Pietro Albini-7/+10
nikomatsakis:nll-fix-issue-issue-btreemap-annotations, r=gankro add outlives annotations to `BTreeMap` NLL requires these annotations, I believe because of <https://github.com/rust-lang/rust/issues/29149>. Fixes #48224 r? @Gankro cc @lqd
2018-07-02Implemented `UnsafeFutureObj` on `Box`Josef Reinhard Brandl-2/+21
2018-07-02Implement `UnsafeFutureObj` for `&mut Future`Josef Reinhard Brandl-1/+3
2018-07-02add outlives annotations to `BTreeMap`Niko Matsakis-7/+10
nll requires these annotations, I believe because of https://github.com/rust-lang/rust/issues/29149
2018-07-02`UnsafeFutureObj` impl for `PinMut`Josef Reinhard Brandl-7/+6
2018-07-02Add lifetime to `FutureObj`Josef Reinhard Brandl-8/+9
2018-07-02Use `From` impls for `FutureObj<()>`Josef Reinhard Brandl-12/+12
2018-07-02Make custom trait object for `Future` genericJosef Reinhard Brandl-15/+15
2018-07-02Make `BTreeMap::clone()` not allocate when cloning an empty tree.Nicholas Nethercote-1/+10
2018-06-30Auto merge of #51717 - Mark-Simulacrum:snap, r=alexcrichtonbors-1/+0
Bootstrap from 1.28.0 beta
2018-06-30Bootstrap from 1.28.0-beta.3Mark Simulacrum-1/+0
2018-06-29liballoc docs: Remove “not intended for general usage”Simon Sapin-4/+4
2018-06-29Rename alloc::arc to alloc::sync, to match std::syncSimon Sapin-3/+3
2018-06-29Remove the Vec and String reexports at the root of the alloc crateSimon Sapin-5/+0
… since `std` has no corresponding reexports. Use `alloc::vec::Vec` and `alloc::string::String` instead.
2018-06-29Move core::alloc::CollectionAllocErr to alloc::collectionsSimon Sapin-5/+34
2018-06-29Move some alloc crate top-level items to a new alloc::collections moduleSimon Sapin-42/+65
This matches std::collections
2018-06-29Remove the unstable alloc::allocator module reexport, deprecated since 1.27Simon Sapin-7/+0