diff --git a/src/types.h b/src/types.h
index 2ca34f8d..a3f3422b 100644
--- a/src/types.h
+++ b/src/types.h
@@ -1441,6 +1441,10 @@ inline uint32 build_bit_ui(uint32 beg, uint32 end)
 {
     assert(end <= 31);
     uint32 myll = 0;
+    if (end > 31)
+    {
+        end = 31;
+    }
     if (end == 31)
     {
         myll = (uint32)(-1);