-avoid overflow in calculation for very large values
authorChristian Grothoff <christian@grothoff.org>
Tue, 26 Jul 2016 20:39:59 +0000 (20:39 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 26 Jul 2016 20:39:59 +0000 (20:39 +0000)
src/util/bandwidth.c

index 008963c3c0d52c8677506ee4e7ec576781b6d9ec..980af764a0638aa954ba0f2b06c6c513368c8f4a 100644 (file)
@@ -203,10 +203,9 @@ update_excess (struct GNUNET_BANDWIDTH_Tracker *av)
   }
   else
   {
+    double factor = 1.0 * left_bytes / (double) av->available_bytes_per_s__; 
     delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
-                                           left_bytes);
-    delay = GNUNET_TIME_relative_divide (delay,
-                                         av->available_bytes_per_s__);
+                                           (unsigned long long) factor);
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "At %llu bps it will take us %s for %lld bytes to reach excess threshold\n",