This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc] Overflow in transfer-rate


In symfile.c/print_transfer_performance (), an overflow can occure when data_count (see below) is a large number.

I propose either the following 1st patch, or to pass to "%llu"into the ui_out_field_fmt functino call, see the next patch proposal.

Index: symfile.c
===================================================================
--- symfile.c   (revision 215)
+++ symfile.c   (working copy)
@@ -1821,7 +1821,7 @@ print_transfer_performance (struct ui_fi
  if (time_count > 0)
    {
      ui_out_field_fmt (uiout, "transfer-rate", "%lu",
-                       1000 * (data_count * 8) / time_count);
+                       ((data_count / time_count) * 8 * 1000);
      ui_out_text (uiout, " bits/sec");
    }
  else




This 2nd option would fix all possible overflow, but I'm not sure yet the %llu is supported under windows.


Index: symfile.c
===================================================================
--- symfile.c   (revision 215)
+++ symfile.c   (working copy)
@@ -1820,13 +1820,13 @@ print_transfer_performance (struct ui_fi
 ui_out_text (uiout, "Transfer rate: ");
 if (time_count > 0)
   {
-      ui_out_field_fmt (uiout, "transfer-rate", "%lu",
-                       1000 * (data_count * 8) / time_count);
+      ui_out_field_fmt (uiout, "transfer-rate", "%llu",
+                       1000ULL * (data_count * 8) / time_count);
     ui_out_text (uiout, " bits/sec");
   }
 else
   {
-      ui_out_field_fmt (uiout, "transferred-bits", "%lu", (data_count * 8));
+      ui_out_field_fmt (uiout, "transferred-bits", "%llu", (data_count * 8ULL));
     ui_out_text (uiout, " bits in <1 sec");
   }
 if (write_count > 0)


Please give me your opinion.


--
Denis


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]