From 396561bdb7a5038c9a277b4bb318305b71a7b8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sat, 17 Oct 2020 19:07:16 +0200 Subject: [PATCH] Make sure arenas don't allocate bigger than HUGE_PAGE --- compiler/rustc_arena/src/lib.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index c051c607ff217..34736b820e963 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -223,10 +223,8 @@ impl TypedArena { // If the previous chunk's len is less than HUGE_PAGE // bytes, then this chunk will be least double the previous // chunk's size. - new_cap = last_chunk.storage.len(); - if new_cap < HUGE_PAGE / elem_size { - new_cap = new_cap.checked_mul(2).unwrap(); - } + new_cap = last_chunk.storage.len().min(HUGE_PAGE / elem_size / 2); + new_cap = new_cap * 2; } else { new_cap = PAGE / elem_size; } @@ -343,10 +341,8 @@ impl DroplessArena { // If the previous chunk's len is less than HUGE_PAGE // bytes, then this chunk will be least double the previous // chunk's size. - new_cap = last_chunk.storage.len(); - if new_cap < HUGE_PAGE { - new_cap = new_cap.checked_mul(2).unwrap(); - } + new_cap = last_chunk.storage.len().min(HUGE_PAGE / 2); + new_cap = new_cap * 2; } else { new_cap = PAGE; }