osd/osdmap: fix divide by zero error #12521
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
*** CID 1397255: Incorrect expression (DIVIDE_BY_ZERO)
/home/brad/working/src/ceph/src/osd/OSDMap.cc: 2995 in
OSDMap::summarize_mapping_stats(OSDMap*, const std::set<long,
std::less, std::allocator> *,
std::__cxx11::basic_string<char, std::char_traits,
std::allocator> *, ceph::Formatter *) const()
2989 f->open_object_section("utilization");
2990 if (newmap) {
2991 if (f) {
2992 f->dump_unsigned("moved_pgs", moved_pg);
2993 f->dump_unsigned("total_pgs", total_pg);
2994 } else {
division by expression "total_pg" which may be zero has undefined
behavior.
2995 ss << "moved " << moved_pg << " / " << total_pg
2996 << " (" << ((float)moved_pg * 100.0 / (float)total_pg) <<
"%)\n";
2997 }
2998 }
2999 if (f) {
3000 f->dump_float("avg_pgs", avg_pg);
Signed-off-by: Yunchuan Wen yunchuan.wen@kylin-cloud.com