From aa92e33194ef5a8157ab4b36992259ecf77c2ccd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 21 Mar 2018 13:51:47 -0400 Subject: [PATCH] bit_util: Do nothing in RotateRight if the rotation amount is zero Without this sanitizing it's possible to perform a shift with a shift amount that's the same size as the type being shifted. This actually occurs when decoding ORR variants. We could get fancier here and make this branchless, but we don't really use RotateRight in any performance intensive areas. --- src/common/bit_util.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/bit_util.h b/src/common/bit_util.h index ae4f83cc..775ccda0 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -130,6 +130,11 @@ inline T Replicate(T value, size_t element_size) { template inline T RotateRight(T value, size_t amount) { amount %= BitSize(); + + if (amount == 0) { + return value; + } + auto x = static_cast>(value); return static_cast((x >> amount) | (x << (BitSize() - amount))); }