]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix 0/0 calculation in get_weighted_fractional_uptime().
authorNick Mathewson <nickm@torproject.org>
Sun, 28 Sep 2008 15:48:36 +0000 (15:48 +0000)
committerNick Mathewson <nickm@torproject.org>
Sun, 28 Sep 2008 15:48:36 +0000 (15:48 +0000)
svn:r16994

ChangeLog
src/or/rephist.c

index aa1abac5fd80b4f287799dd9ffdc487d7440a1d4..b3eb32ed883503b2b935e14f0df82fddc77549ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -66,6 +66,8 @@ Changes in version 0.2.1.6-alpha - 2008-09-xx
       directory writes.  Previously, we had only counted this when we
       had met our limits precisely. Fixes bug 824. Patch from by rovv.
       Bugfix on 0.2.0.x (??).
+    - Avoid a 0/0 calculation when calculating router uptime at directory
+      authorities.  Bugfix on 0.2.0.8-alpha.
 
   o Minor bugfixes (controller):
     - Make DNS resolved events into "CLOSED", not "FAILED".  Bugfix on
index 76f31652353c186cca621a9c1c5b0eec30042e79..8019be7257dfa2fb734caf93bca6fb85cc6aea08 100644 (file)
@@ -462,6 +462,14 @@ get_weighted_fractional_uptime(or_history_t *hist, time_t when)
   } else if (hist->start_of_downtime) {
     total += (when - hist->start_of_downtime);
   }
+
+  if (!total) {
+    /* Avoid calling anybody's uptime infinity (which should be impossible if
+     * the code is working), or NaN (which can happen for any router we haven't
+     * observed up or down yet). */
+    return 0.0;
+  }
+
   return ((double) up) / total;
 }