diff options
| author | Sebastian Hahn <sebastian@torproject.org> | 2020-02-17 18:55:41 +0100 |
|---|---|---|
| committer | Sebastian Hahn <sebastian@torproject.org> | 2020-02-18 23:57:48 +0100 |
| commit | 3e17d191fa47b9ab262d0efa3a39e500e9fb1667 (patch) | |
| tree | 6836e41cf732613d926f82d381398bcbc14348e9 /src/test | |
| parent | 0176a9eef845e7421b7e2f7ef015333a41a7c027 (diff) | |
| download | rust-3e17d191fa47b9ab262d0efa3a39e500e9fb1667.tar.gz rust-3e17d191fa47b9ab262d0efa3a39e500e9fb1667.zip | |
Revert "Remove `checked_add` in `Layout::repeat`"
This fixes a a segfault in safe code, a stable regression. Reported in \#69225. This reverts commit a983e0590a43ed8b0f60417828efd4e79b51f494. Also adds a test for the expected behaviour.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs b/src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs new file mode 100644 index 00000000000..7f43e4d1a51 --- /dev/null +++ b/src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs @@ -0,0 +1,31 @@ +// Ensure we appropriately error instead of overflowing a calculation when creating a new Alloc +// Layout + +// run-fail +// compile-flags: -C opt-level=3 +// error-pattern: index out of bounds: the len is 0 but the index is 16777216 +// ignore-wasm no panic or subprocess support +// ignore-emscripten no panic or subprocess support + +fn do_test(x: usize) { + let arr = vec![vec![0u8; 3]]; + + let mut z = Vec::new(); + for arr_ref in arr { + for y in 0..x { + for _ in 0..1 { + z.extend(std::iter::repeat(0).take(x)); + let a = y * x; + let b = (y + 1) * x - 1; + let slice = &arr_ref[a..b]; + eprintln!("{} {} {} {}", a, b, arr_ref.len(), slice.len()); + eprintln!("{:?}", slice[1 << 24]); + } + } + } +} + +fn main() { + do_test(1); + do_test(2); +} |
