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 <odanrc@yahoo.com.br> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27104 Tested-by: Gem5 Cloud Project GCB service account <345032938727@cloudbuild.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
This commit is contained in:
committed by
Daniel Carvalho
parent
64134b6e66
commit
ffad8a370a
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user