diff --git a/ortools/util/bitset.h b/ortools/util/bitset.h index 62bb9f0554..45be84d84e 100644 --- a/ortools/util/bitset.h +++ b/ortools/util/bitset.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -452,7 +453,14 @@ class Bitset64 { void resize(int size) { Resize(IndexType(size)); } void Resize(IndexType size) { DCHECK_GE(Value(size), 0); - size_ = Value(size) > 0 ? size : IndexType(0); + IndexType new_size = Value(size) > 0 ? size : IndexType(0); + if (new_size < size_ && Value(new_size) > 0) { + const int64_t new_data_size = BitLength64(Value(new_size)); + const uint64_t bitmask = kAllBitsButLsb64 + << BitPos64(Value(new_size) - 1); + data_[new_data_size - 1] &= ~bitmask; + } + size_ = new_size; data_.resize(BitLength64(Value(size_)), 0); }