From abc3ad95e63615f7783c20c7ff29a4e3251e2e35 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 1 Jan 2022 18:23:08 +0100 Subject: [PATCH] Return value of correct width for dynamic array out-of-bound access Commit e1870acfacc9 ("Return the correct value when a queue or darray references an undefined element") added support for specifying the width of the vector elements stored in a queue or dynamic array, so that an out-of-bounds access can create a word with the right width. To get the element width of a queue or dynamic array it uses the `packed_width()` method. But this method is only implemented for `netqueue_t` and returns always 1 for dynamic arrays. As a result out-of-bounds access on a dynamic array will push a vector of the wrong width onto the stack if the vector element is wider than 1 bit. This will usually trigger an assert in vvp. Fix this by moving the `packed_width()` method implementation from `netqueue_t` to its base class `netdarray_t` so that it works for all types of dynamic arrays. Signed-off-by: Lars-Peter Clausen --- netdarray.h | 3 +++ netqueue.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/netdarray.h b/netdarray.h index 326f07d4c..890995ad1 100644 --- a/netdarray.h +++ b/netdarray.h @@ -36,6 +36,9 @@ class netdarray_t : public netarray_t { // A dynamic array may have a type that is signed. inline bool get_signed() const { return element_type()->get_signed(); } + // Use the packed width to pass the element width + long packed_width() const { return element_type()->packed_width(); } + // This is the base_type() of the element of the array. We // need this in some cases in order to get the base type of // the element, and not the IVL_VT_DARRAY of the array itself. diff --git a/netqueue.h b/netqueue.h index 13061ca33..1e04e4535 100644 --- a/netqueue.h +++ b/netqueue.h @@ -38,9 +38,6 @@ class netqueue_t : public netdarray_t { // IVL_VT_QUEUE for queues. ivl_variable_type_t base_type() const; - // Use the packed width to pass the element width - long packed_width(void) const { return element_type()->packed_width(); } - long max_idx(void) const { return max_idx_; } std::ostream& debug_dump(std::ostream&) const;