diff options
author | Peter Åstrand (astrand) <astrand@cendio.se> | 2018-05-29 10:04:53 +0200 |
---|---|---|
committer | Peter Åstrand (astrand) <astrand@cendio.se> | 2018-05-29 10:04:53 +0200 |
commit | c05fba745ee42661b54bb4454b270e43232c1bcc (patch) | |
tree | ed46d37fe60ab1587c1a369bd388b9be96e62ba5 | |
parent | e7b333da0797a4828f3e169729e6da0e1f51c7be (diff) | |
download | tigervnc-c05fba745ee42661b54bb4454b270e43232c1bcc.tar.gz tigervnc-c05fba745ee42661b54bb4454b270e43232c1bcc.zip |
Avoid assert crash after bytestream position wrap around
Fixes #652.
-rw-r--r-- | common/rfb/Congestion.cxx | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/common/rfb/Congestion.cxx b/common/rfb/Congestion.cxx index 4d36d9f1..8162808b 100644 --- a/common/rfb/Congestion.cxx +++ b/common/rfb/Congestion.cxx @@ -68,6 +68,11 @@ static const unsigned MINIMUM_WINDOW = 4096; // limit for now... static const unsigned MAXIMUM_WINDOW = 4194304; +// Compare position even when wrapped around +static inline bool isAfter(unsigned a, unsigned b) { + return (int)a - (int)b > 0; +} + static LogWriter vlog("Congestion"); Congestion::Congestion() : @@ -230,7 +235,7 @@ int Congestion::getUncongestedETA() targetAcked = lastPosition - congWindow; // Simple case? - if (lastPong.pos > targetAcked) + if (isAfter(lastPong.pos, targetAcked)) return 0; // No measurements yet? @@ -269,7 +274,7 @@ int Congestion::getUncongestedETA() etaNext -= delay; // Found it? - if (curPing.pos > targetAcked) { + if (isAfter(curPing.pos, targetAcked)) { eta += etaNext * (curPing.pos - targetAcked) / (curPing.pos - prevPing->pos); if (elapsed > eta) return 0; |