gcc/ChangeLog:

2017-04-27  Martin Liska  <mli...@suse.cz>

        PR gcov-profile/53915
        * gcov.c (format_gcov): Print 'NAN %' when top > bottom.
---
 gcc/gcov.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 0adb4466f70..22378583c5c 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1942,6 +1942,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.12.2


Reply via email to