I'll cast those. Sorry I missed that. -----Original Message----- From: Gedare Bloom <ged...@rtems.org> Sent: Tuesday, June 29, 2021 2:03 PM To: Ryan Long <ryan.l...@oarcorp.com> Cc: devel@rtems.org Subject: Re: [PATCH v2 2/2] rtems-exeinfo.cpp: Fix division by zero errors
On Tue, Jun 29, 2021 at 11:50 AM Ryan Long <ryan.l...@oarcorp.com> wrote: > > CID 1503008: Division or modulo by zero CID 1503015: Division or > modulo by zero > > Closes #4416 > --- > linkers/rtems-exeinfo.cpp | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/linkers/rtems-exeinfo.cpp b/linkers/rtems-exeinfo.cpp > index 1e6d4b4..ec51597 100644 > --- a/linkers/rtems-exeinfo.cpp > +++ b/linkers/rtems-exeinfo.cpp > @@ -755,6 +755,8 @@ namespace rld > size_t total = 0; > size_t total_size = 0; > size_t inlined_size = 0; > + double percentage; > + double percentage_size; > dwarf::functions funcs_inlined; > dwarf::functions funcs_not_inlined; > func_counts counts; > @@ -798,14 +800,24 @@ namespace rld > } > } > > + if ( total == 0 ) { > + percentage = 0; > + } else { > + percentage = ( funcs_inlined.size() * 100 ) / total; > + } > + > + if ( total_size == 0 ) { > + percentage_size = 0; > + } else { > + percentage_size = ( inlined_size * 100 ) / total_size; These are still integer results. If you want double, you should cast, if you want integer, you should use int type for the percentage and percentage_size variables. > + } > + > std::cout << "inlined funcs : " << funcs_inlined.size () << std::endl > << " total funcs : " << total << std::endl > - << " % inline funcs : " << (funcs_inlined.size () * 100) / > total << '%' > - << std::endl > + << " % inline funcs : " << percentage << '%' << > + std::endl > << " total size : " << total_size << std::endl > << " inline size : " << inlined_size << std::endl > - << " % inline size : " << (inlined_size * 100) / total_size > << '%' > - << std::endl; > + << " % inline size : " << percentage_size << '%' << > + std::endl; > > auto count_compare = [](func_count const & a, func_count const & b) { > return a.size != b.size? a.size < b.size : a.count > > b.count; > -- > 1.8.3.1 > > _______________________________________________ > devel mailing list > devel@rtems.org > http://lists.rtems.org/mailman/listinfo/devel _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel