Fix BitVector::SetInitialBits().

Change-Id: Iad3699d76ad69536aa4810329f5863bc995f6551
diff --git a/runtime/base/bit_vector.cc b/runtime/base/bit_vector.cc
index 3db8e12..590835e 100644
--- a/runtime/base/bit_vector.cc
+++ b/runtime/base/bit_vector.cc
@@ -265,6 +265,7 @@
   uint32_t rem_num_bits = num_bits & 0x1f;
   if (rem_num_bits != 0) {
     storage_[idx] = (1 << rem_num_bits) - 1;
+    ++idx;
   }
 
   // Now set the upper ones to 0.
diff --git a/runtime/base/bit_vector_test.cc b/runtime/base/bit_vector_test.cc
index 3fc9b86..a67fb33 100644
--- a/runtime/base/bit_vector_test.cc
+++ b/runtime/base/bit_vector_test.cc
@@ -119,4 +119,23 @@
   EXPECT_EQ(4U, bv.NumSetBits(63));
 }
 
+TEST(BitVector, SetInitialBits) {
+  const uint32_t kWords = 2;
+
+  uint32_t bits[kWords];
+  memset(bits, 0, sizeof(bits));
+
+  BitVector bv(0U, false, Allocator::GetNoopAllocator(), kWords, bits);
+  bv.SetInitialBits(0u);
+  EXPECT_EQ(0u, bv.NumSetBits());
+  bv.SetInitialBits(1u);
+  EXPECT_EQ(1u, bv.NumSetBits());
+  bv.SetInitialBits(32u);
+  EXPECT_EQ(32u, bv.NumSetBits());
+  bv.SetInitialBits(63u);
+  EXPECT_EQ(63u, bv.NumSetBits());
+  bv.SetInitialBits(64u);
+  EXPECT_EQ(64u, bv.NumSetBits());
+}
+
 }  // namespace art