]> source.dussan.org Git - tigervnc.git/commitdiff
Don't shuffle input buffer unless actually needed
authorPierre Ossman <ossman@cendio.se>
Sat, 16 May 2020 09:32:26 +0000 (11:32 +0200)
committerPierre Ossman <ossman@cendio.se>
Thu, 21 May 2020 09:34:22 +0000 (11:34 +0200)
common/rdr/BufferedInStream.cxx

index 64cdb667c3041f590ada4c120ce9c52dc3b78a9c..967e5a54289a24de674f7d141dbcad5b843b3c66 100644 (file)
@@ -51,12 +51,14 @@ bool BufferedInStream::overrun(size_t needed, bool wait)
                     "requested size of %lu bytes exceeds maximum of %lu bytes",
                     (long unsigned)needed, (long unsigned)bufSize);
 
-  if (end - ptr != 0)
+  // Do we need to shuffle things around?
+  if ((bufSize - (ptr - start)) < needed) {
     memmove(start, ptr, end - ptr);
 
-  offset += ptr - start;
-  end -= ptr - start;
-  ptr = start;
+    offset += ptr - start;
+    end -= ptr - start;
+    ptr = start;
+  }
 
   while (avail() < needed) {
     if (!fillBuffer(start + bufSize - end, wait))