From f6e5ea302766e080881c24b0ac19dcf3a46b4e65 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Tue, 25 Nov 2025 19:06:46 +0100 Subject: [PATCH] newcelltypes: bounds check --- kernel/newcelltypes.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/newcelltypes.h b/kernel/newcelltypes.h index 0379eda05..b25a690ca 100644 --- a/kernel/newcelltypes.h +++ b/kernel/newcelltypes.h @@ -410,7 +410,10 @@ struct Categories { struct Category { std::array data{}; constexpr bool operator()(IdString type) const { - return data[type.index_]; + size_t idx = type.index_; + if (idx >= MAX_CELLS) + return false; + return data[idx]; } constexpr bool& operator[](size_t idx) { return data[idx]; @@ -496,12 +499,14 @@ struct NewCellType { struct NewCellTypes { StaticCellTypes::Categories::Category static_cell_types = StaticCellTypes::categories.empty; - dict custom_cell_types; + dict custom_cell_types = {}; NewCellTypes() { + static_cell_types = StaticCellTypes::categories.empty; } NewCellTypes(RTLIL::Design *design) { + static_cell_types = StaticCellTypes::categories.empty; setup(design); } void setup(RTLIL::Design *design = NULL) {