If nbits is 64 (or greater) then shifting 1ULL left is undefined.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/util/virrandom.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/util/virrandom.c b/src/util/virrandom.c
index 3c011a8615..7915f6531e 100644
--- a/src/util/virrandom.c
+++ b/src/util/virrandom.c
@@ -68,7 +68,9 @@ uint64_t virRandomBits(int nbits)
return 0;
}
- ret &= (1ULL << nbits) - 1;
+ if (nbits < 64)
+ ret &= (1ULL << nbits) - 1;
+
return ret;
}
--
2.16.4