From: Pierre Ossman Date: Sat, 16 May 2020 09:32:26 +0000 (+0200) Subject: Don't shuffle input buffer unless actually needed X-Git-Tag: v1.11.90~74^2~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c2bbdb573d546eb88539d1204b84cb48d910191a;p=tigervnc.git Don't shuffle input buffer unless actually needed --- diff --git a/common/rdr/BufferedInStream.cxx b/common/rdr/BufferedInStream.cxx index 64cdb667..967e5a54 100644 --- a/common/rdr/BufferedInStream.cxx +++ b/common/rdr/BufferedInStream.cxx @@ -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))