Isaac Sánchez Barrera has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/37617 )

Change subject: base: Prevent undefined behavior in not interleaved `AddrRange`s.
......................................................................

base: Prevent undefined behavior in not interleaved `AddrRange`s.

If an `AddrRange` is not interleaved, return the input address in
`removeIntlvBits` and `addIntlvBits` to prevent undefined behavior.  It
allows to use these methods in all cases without having to check manually
whether the range is interleaved.

Change-Id: Ic6ac8c4e52b09417bc41aa9380a24319c34e0b35
Signed-off-by: Isaac Sánchez Barrera <isaac.sanc...@bsc.es>
---
M src/base/addr_range.hh
1 file changed, 13 insertions(+), 1 deletion(-)



diff --git a/src/base/addr_range.hh b/src/base/addr_range.hh
index 8a811d4..7572d97 100644
--- a/src/base/addr_range.hh
+++ b/src/base/addr_range.hh
@@ -473,12 +473,18 @@
      * ---------------------------------
      *
      * @param a the input address
-     * @return the new address
+     * @return the new address, or the input address if not interleaved
      *
      * @ingroup api_addr_range
      */
     inline Addr removeIntlvBits(Addr a) const
     {
+        // Directly return the address if the range is not interleaved
+        // to prevent undefined behavior.
+        if (!interleaved()) {
+            return a;
+        }
+
         // Get the LSB set from each mask
         int masks_lsb[masks.size()];
         for (int i = 0; i < masks.size(); i++) {
@@ -511,6 +517,12 @@
      */
     inline Addr addIntlvBits(Addr a) const
     {
+        // Directly return the address if the range is not interleaved
+        // to prevent undefined behavior.
+        if (!interleaved()) {
+            return a;
+        }
+
         // Get the LSB set from each mask
         int masks_lsb[masks.size()];
         for (int i = 0; i < masks.size(); i++) {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/37617
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ic6ac8c4e52b09417bc41aa9380a24319c34e0b35
Gerrit-Change-Number: 37617
Gerrit-PatchSet: 1
Gerrit-Owner: Isaac Sánchez Barrera <isaac.sanc...@bsc.es>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to