From: Arnaud Giersch Date: Thu, 15 Mar 2012 15:46:52 +0000 (+0100) Subject: Bug fix: credit can be negative. X-Git-Tag: exp_20120315~1 X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/commitdiff_plain/162ec6e7763efa260523f5cf03f635159803947d?ds=sidebyside;hp=40b4277000058eaab29f7d74a31a327ce2d1b700 Bug fix: credit can be negative. E.g. when a data message comes faster than its corresponding ctrl message. Check that it is not negative when computing balance. --- diff --git a/process.cpp b/process.cpp index 97f2a69..b5531b0 100644 --- a/process.cpp +++ b/process.cpp @@ -421,7 +421,11 @@ void process::data_send(neighbor& nb) else excess_load = real_load; - double balance = nb.get_debt() - nb.get_credit(); + double balance; + if (nb.get_credit() > 0.0) + balance = nb.get_debt() - nb.get_credit(); + else + balance = nb.get_debt(); load_to_send = std::min(excess_load, std::max(0.0, balance));