Fix UB in folly/experimental/Bits.h
[folly.git] / folly / experimental / test / BitsTest.cpp
index aeff9d35e511af0b5383022848049227c0c675fd..0a1ec16d97c86f7b2614101b4953bcd8ee32b7a7 100644 (file)
@@ -255,6 +255,17 @@ T testValue(int bits) {
 }
 } // anonymous namespace
 
+TEST(Bits, Boundaries) {
+  uint8_t buf[20];
+  for (size_t offset = 0; offset <= 64; ++offset) {
+    for (size_t size = 0; size <= 32; ++size) {
+      int32_t value = testValue<int32_t>(size);
+      testSet<true>(buf, offset, size, value);
+      EXPECT_EQ(value, (testGet<true, int32_t>(buf, offset, size)));
+    }
+  }
+}
+
 template <size_t N>
 void accSize(size_t& w) {
   for (size_t s = 0; s <= N; ++s) {