Print a valid hex (0x0) during empty feature bit, so that the clients could recognize it.
When the _vec size becomes 0, print() function creates an invalid hex (0x) and 'perf stats'
crashes with the below error:
"
File "/opt/ceph/src/pybind/mgr/stats/fs/perf_stats.py", line 177, in notify_cmd
metric_features = int(metadata[CLIENT_METADATA_KEY]["metric_spec"]["metric_flags"]["feature_bits"], 16)
ValueError: invalid literal for int() with base 16: '0x'
"
This patch creates a valid hex (0x0), when _vec size is 0.
Fixes: https://tracker.ceph.com/issues/59551
Signed-off-by: Jos Collin <jcollin@redhat.com>
void feature_bitset_t::print(ostream& out) const
{
std::ios_base::fmtflags f(out.flags());
- out << "0x";
- for (int i = _vec.size() - 1; i >= 0; --i)
- out << std::setfill('0') << std::setw(sizeof(block_type) * 2)
- << std::hex << _vec[i];
+ int size = _vec.size();
+ if (!size) {
+ out << "0x0";
+ } else {
+ out << "0x";
+ for (int i = size - 1; i >= 0; --i)
+ out << std::setfill('0') << std::setw(sizeof(block_type) * 2)
+ << std::hex << _vec[i];
+ }
out.flags(f);
}