Ticket #20796: 0008-Avoid-division-by-zero-and-excessive-ranks-in-ScanHa.patch

File 0008-Avoid-division-by-zero-and-excessive-ranks-in-ScanHa.patch, 1.2 KB (added by teor, 3 years ago)

Patch for this issue

  • ScanSupport.py

    From 0f3136c068f0999056df239643dca4db262a6a39 Mon Sep 17 00:00:00 2001
    From: teor <teor2345@gmail.com>
    Date: Sun, 27 Nov 2016 19:46:13 +1100
    Subject: [PATCH 8/9] Avoid division by zero and excessive ranks in
     ScanHandler.rank_to_percent
    
    Signed-off-by: teor <teor2345@gmail.com>
    ---
     ScanSupport.py | 10 ++++++++--
     1 file changed, 8 insertions(+), 2 deletions(-)
    
    diff --git a/ScanSupport.py b/ScanSupport.py
    index d3bfbc1..1e4e989 100644
    a b class ScanHandler(PathSupport.PathBuilder): 
    131131      # This is ugly. If we are only scanning the unmeasured routers,
    132132      # we need a special count of just them..
    133133      if this.selmgr.only_unmeasured:
    134         # XXX: This can exceed 100%
    135134        count = 0
    136135        for r in this.sorted_r:
    137136          if r.unmeasured: count += 1
    138137      else:
    139138        count = len(this.sorted_r)
    140       cond._pct = (100.0*rank)/count # XXX: Div 0 here if no unmeasured..
     139      if count == 0:
     140        # XXX: Div 0 here if no unmeasured..
     141        cond._pct = 0.0
     142      elif rank > count:
     143        # XXX: This can exceed 100%
     144        cond._pct = 100.0
     145      else:
     146        cond._pct = (100.0*rank)/count
    141147      cond.notify()
    142148      cond.release()
    143149    cond.acquire()