diff options
| author | Martin Liska <mliska@suse.cz> | 2018-07-26 10:50:21 +0200 |
|---|---|---|
| committer | Martin Liska <marxin@gcc.gnu.org> | 2018-07-26 08:50:21 +0000 |
| commit | 977667e6b74a56db3747caaed8ba776f6cae8cdf (patch) | |
| tree | f468ca975fd865c0d7797df158bad531b2c05eed /gcc/gcov.c | |
| parent | 6dd580109f5297ae467d3c32204530a735925ba9 (diff) | |
| download | gcc-977667e6b74a56db3747caaed8ba776f6cae8cdf.zip gcc-977667e6b74a56db3747caaed8ba776f6cae8cdf.tar.gz gcc-977667e6b74a56db3747caaed8ba776f6cae8cdf.tar.bz2 | |
gcov: Fix wrong usage of NAN in statistics (PR gcov-profile/86536).
2018-07-26 Martin Liska <mliska@suse.cz>
PR gcov-profile/86536
* gcov.c (format_gcov): Use printf format %.*f directly
and do not handle special values.
2018-07-26 Martin Liska <mliska@suse.cz>
PR gcov-profile/86536
* gcc.misc-tests/gcov-pr86536.c: New test.
From-SVN: r262991
Diffstat (limited to 'gcc/gcov.c')
| -rw-r--r-- | gcc/gcov.c | 46 |
1 files changed, 10 insertions, 36 deletions
@@ -2203,50 +2203,24 @@ format_count (gcov_type count) } /* Format a GCOV_TYPE integer as either a percent ratio, or absolute - count. If dp >= 0, format TOP/BOTTOM * 100 to DP decimal places. - If DP is zero, no decimal point is printed. Only print 100% when - TOP==BOTTOM and only print 0% when TOP=0. If dp < 0, then simply + count. If DECIMAL_PLACES >= 0, format TOP/BOTTOM * 100 to DECIMAL_PLACES. + If DECIMAL_PLACES is zero, no decimal point is printed. Only print 100% when + TOP==BOTTOM and only print 0% when TOP=0. If DECIMAL_PLACES < 0, then simply format TOP. Return pointer to a static string. */ static char const * -format_gcov (gcov_type top, gcov_type bottom, int dp) +format_gcov (gcov_type top, gcov_type bottom, int decimal_places) { static char buffer[20]; - /* Handle invalid values that would result in a misleading value. */ - if (bottom != 0 && top > bottom && dp >= 0) + if (decimal_places >= 0) { - sprintf (buffer, "NAN %%"); - return buffer; - } + float ratio = bottom ? 100.0f * top / bottom: 0; - if (dp >= 0) - { - float ratio = bottom ? (float)top / bottom : 0; - int ix; - unsigned limit = 100; - unsigned percent; - - for (ix = dp; ix--; ) - limit *= 10; - - percent = (unsigned) (ratio * limit + (float)0.5); - if (percent <= 0 && top) - percent = 1; - else if (percent >= limit && top != bottom) - percent = limit - 1; - ix = sprintf (buffer, "%.*u%%", dp + 1, percent); - if (dp) - { - dp++; - do - { - buffer[ix+1] = buffer[ix]; - ix--; - } - while (dp--); - buffer[ix + 1] = '.'; - } + /* Round up to 1% if there's a small non-zero value. */ + if (ratio > 0.0f && ratio < 0.5f && decimal_places == 0) + ratio = 1.0f; + sprintf (buffer, "%.*f%%", decimal_places, ratio); } else return format_count (top); |
