]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add an assertion to try to please coverity.
authorNick Mathewson <nickm@torproject.org>
Fri, 28 Jul 2017 14:17:14 +0000 (10:17 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 28 Jul 2017 14:17:57 +0000 (10:17 -0400)
Coverity, for some reason, thought that weight_scale might be 0,
leading to a divide-by-zero error.

src/or/routerparse.c

index f4e87a00d84500db3dad0890e3861f947b730a6d..8823c0b53e6d0bcfdc1ee9586cc45df4d2951a6d 100644 (file)
@@ -2854,7 +2854,6 @@ compare_vote_routerstatus_entries(const void **_a, const void **_b)
 int
 networkstatus_verify_bw_weights(networkstatus_t *ns, int consensus_method)
 {
-  int64_t weight_scale;
   int64_t G=0, M=0, E=0, D=0, T=0;
   double Wgg, Wgm, Wgd, Wmg, Wmm, Wme, Wmd, Weg, Wem, Wee, Wed;
   double Gtotal=0, Mtotal=0, Etotal=0;
@@ -2862,7 +2861,8 @@ networkstatus_verify_bw_weights(networkstatus_t *ns, int consensus_method)
   int valid = 1;
   (void) consensus_method;
 
-  weight_scale = networkstatus_get_weight_scale_param(ns);
+  const int64_t weight_scale = networkstatus_get_weight_scale_param(ns);
+  tor_assert(weight_scale >= 1);
   Wgg = networkstatus_get_bw_weight(ns, "Wgg", -1);
   Wgm = networkstatus_get_bw_weight(ns, "Wgm", -1);
   Wgd = networkstatus_get_bw_weight(ns, "Wgd", -1);