From 99755f374d6fa3a7797677f25ff913ea55c89cdd Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 28 Sep 2008 15:48:36 +0000 Subject: Fix 0/0 calculation in get_weighted_fractional_uptime(). svn:r16994 --- src/or/rephist.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/or/rephist.c') diff --git a/src/or/rephist.c b/src/or/rephist.c index 76f3165235..8019be7257 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -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; } -- cgit v1.2.3-54-g00ecf