1
0
Fork 0

(svn r25391) -Fix: make ChangeShare really aware of INT_MIN

release/1.4
fonsinchen 2013-06-10 21:53:11 +00:00
parent 06d95e9123
commit 1c995a3faa
1 changed files with 20 additions and 14 deletions

View File

@ -4101,27 +4101,33 @@ void FlowStat::ChangeShare(StationID st, int flow)
* be empty. In that case the whole flow stat must be deleted then. */ * be empty. In that case the whole flow stat must be deleted then. */
assert(!this->shares.empty()); assert(!this->shares.empty());
int32 added_shares = 0; uint removed_shares = 0;
uint32 last_share = 0; uint added_shares = 0;
uint last_share = 0;
SharesMap new_shares; SharesMap new_shares;
for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) { for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
if (it->second == st) { if (it->second == st) {
uint share = it->first - last_share; if (flow < 0) {
int change = flow - added_shares; uint share = it->first - last_share;
uint new_share = (change < 0 && (uint)(-change) > share) ? 0 : share + change; if (flow == INT_MIN || (uint)(-flow) >= share) {
added_shares -= share; removed_shares += share;
added_shares += new_share; if (flow != INT_MIN) flow += share;
if (new_share > 0) { last_share = it->first;
new_shares[it->first + added_shares] = it->second; continue; // remove the whole share
}
removed_shares += (uint)(-flow);
} else {
added_shares += (uint)(flow);
} }
} else {
new_shares[it->first + added_shares] = it->second; /* If we don't continue above the whole flow has been added or
* removed. */
flow = 0;
} }
new_shares[it->first + added_shares - removed_shares] = it->second;
last_share = it->first; last_share = it->first;
} }
if (flow > added_shares) { if (flow > 0) new_shares[last_share + (uint)flow] = st;
new_shares[last_share + flow - added_shares] = st;
}
this->shares.swap(new_shares); this->shares.swap(new_shares);
} }