log_histogram: log_heap_options::bucket_of: avoid calling pow2_rank(0)

pow2_rank is undefined for 0.
bucket_of currently works around that by using a bitmask of 0.
To allow asserting that count_{leading,trailing}_zeros are not
called with 0, we want to avoid it at all call sites.

Fixes #4153

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Message-Id: <20190623162137.2401-1-bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2019-06-23 19:21:37 +03:00
committed by Avi Kivity
parent 779b378785
commit b1e78313fe

View File

@@ -59,6 +59,11 @@ struct log_heap_options {
}
size_t bucket_of(size_t value) const {
#ifdef __SANITIZE_ADDRESS__
if (value < min_size) {
return 0;
}
#endif
const auto min_mask = -size_t(value >= min_size); // 0 when below min_size, all bits on otherwise
value = value - min_size + 1;
const auto pow2_index = pow2_rank(value);