From 07ea19a797c6087725fe5b9f2630871c52020311 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 28 Apr 2017 14:51:22 +0200 Subject: [PATCH] Fix format_gcov to not print misleading values (PR gcov-profile/53915) 2017-04-28 Martin Liska PR gcov-profile/53915 * gcov.c (format_gcov): Print 'NAN %' when top > bottom. From-SVN: r247375 --- gcc/ChangeLog | 5 +++++ gcc/gcov.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 63b6276..608e0e9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2017-04-28 Martin Liska + PR gcov-profile/53915 + * gcov.c (format_gcov): Print 'NAN %' when top > bottom. + +2017-04-28 Martin Liska + PR gcov-profile/79891 * gcov.c (add_line_counts): Assign BBs to lines just if the BB is marked by compiler as living on a line. diff --git a/gcc/gcov.c b/gcc/gcov.c index b25464e..924a5a3 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -1946,6 +1946,13 @@ format_gcov (gcov_type top, gcov_type bottom, int dp) { static char buffer[20]; + /* Handle invalid values that would result in a misleading value. */ + if (bottom != 0 && top > bottom && dp >= 0) + { + sprintf (buffer, "NAN %%"); + return buffer; + } + if (dp >= 0) { float ratio = bottom ? (float)top / bottom : 0; -- 2.7.4