PR25244, --print-memory-usage, division by zero if MEMORY length is zero
authorAlan Modra <amodra@gmail.com>
Thu, 5 Dec 2019 06:07:25 +0000 (16:37 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 5 Dec 2019 07:05:13 +0000 (17:35 +1030)
PR 25244
* ldlang.c (lang_print_memory_usage): Don't print percent used
when length is zero.

ld/ChangeLog
ld/ldlang.c

index adca95ffc0b5aa6f8be46a12e78b0d92444e1d00..15b2d805334bad92a4896ea7cdeaf948fd0fdc7e 100644 (file)
@@ -1,3 +1,9 @@
+2019-12-05  Alan Modra  <amodra@gmail.com>
+
+       PR 25244
+       * ldlang.c (lang_print_memory_usage): Don't print percent used
+       when length is zero.
+
 2019-11-27  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * testsuite/ld-elf/eh5.d: Accept version 3 DWARF CIE.
index 191d8f1c61dfa016970ddeb0dd7b14b25e59701c..bb3cd912157ec76795f49cecdf98897cfa3c7282 100644 (file)
@@ -9273,14 +9273,15 @@ lang_print_memory_usage (void)
   for (r = lang_memory_region_list; r->next != NULL; r = r->next)
     {
       bfd_vma used_length = r->current - r->origin;
-      double percent;
 
       printf ("%16s: ",r->name_list.name);
       lang_print_memory_size (used_length);
       lang_print_memory_size ((bfd_vma) r->length);
 
-      percent = used_length * 100.0 / r->length;
-
-      printf ("    %6.2f%%\n", percent);
+      if (r->length != 0)
+       {
+         double percent = used_length * 100.0 / r->length;
+         printf ("    %6.2f%%\n", percent);
+       }
     }
 }