Skip to content

Commit

Permalink
Avoid assert crash after bytestream position wrap around
Browse files Browse the repository at this point in the history
Fixes #652.
  • Loading branch information
Peter Åstrand (astrand) committed May 29, 2018
1 parent e7b333d commit c05fba7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions common/rfb/Congestion.cxx
Expand Up @@ -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() :
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c05fba7

Please sign in to comment.