Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/27104 )

Change subject: base: Fix undefined behavior in mask generation
......................................................................

base: Fix undefined behavior in mask generation

When generating a mask, if the number of bits is greater than
the maximum shift distance (63), the shift will have undefined
behavior. Previously the branch was taking care of a single
trespassing case, and it has been fixed to cover the remaining.

Issue-on: https://gem5.atlassian.net/browse/GEM5-205

Change-Id: Ib5a00917c8d2b23ffdb710c2f9673d956cd9f43e
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
---
M src/base/bitfield.hh
1 file changed, 5 insertions(+), 2 deletions(-)



diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh
index 9a252a4..c2ed72b 100644
--- a/src/base/bitfield.hh
+++ b/src/base/bitfield.hh
@@ -50,12 +50,15 @@
 extern const uint8_t reverseLookUpTable[];

 /**
- * Generate a 64-bit mask of 'nbits' 1s, right justified.
+ * Generate a 64-bit mask of 'nbits' 1s, right justified. If a number of bits
+ * greater than 64 is given, it is truncated to 64.
+ *
+ * @param nbits The number of bits set in the mask.
  */
 inline uint64_t
 mask(int nbits)
 {
-    return (nbits == 64) ? (uint64_t)-1LL : (1ULL << nbits) - 1;
+    return (nbits >= 64) ? (uint64_t)-1LL : (1ULL << nbits) - 1;
 }

 /**

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27104
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: Ib5a00917c8d2b23ffdb710c2f9673d956cd9f43e
Gerrit-Change-Number: 27104
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to