osd/osdmap: fix divide by zero error #12521

Merged
merged 1 commit into from Dec 16, 2016

Projects

None yet

2 participants

@wwformat
Contributor

*** 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 {

CID 1397255:  Incorrect expression  (DIVIDE_BY_ZERO)
In expression "(float)moved_pg * 100. / (float)total_pg",

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

@wwformat wwformat osdmap: fix divide by zero error
*** 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<long>, std::allocator<long>> *,
std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char>> *, 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 {
>>>     CID 1397255:  Incorrect expression  (DIVIDE_BY_ZERO)
>>>     In expression "(float)moved_pg * 100. / (float)total_pg",
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>
61d3e4f
@liewegas liewegas changed the title from osdmap: fix divide by zero error to osd/osdmap: fix divide by zero error Dec 16, 2016
@liewegas liewegas merged commit 15fdc67 into ceph:master Dec 16, 2016

3 checks passed

Signed-off-by all commits in this PR are signed
Details
Unmodifed Submodules submodules for project are unmodified
Details
default Build finished.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment