From: Alex Rousskov Date: Sun, 26 Jul 2015 18:16:34 +0000 (-0600) Subject: When SBuf chop()s away everything, always clear the buffer. X-Git-Tag: merge-candidate-3-v1~29^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80ec003619c64b73a5932d1015e2a4baf95a6266;p=thirdparty%2Fsquid.git When SBuf chop()s away everything, always clear the buffer. The old code was trying to make the clearance decision without normalizing parameters first and missed most cases as the result. In theory, clear()ing SBuf during chop() is just an optimization that should have no effect on correct code functionality. --- diff --git a/src/SBuf.cc b/src/SBuf.cc index 1c40c9c95e..412f2fde39 100644 --- a/src/SBuf.cc +++ b/src/SBuf.cc @@ -565,12 +565,18 @@ SBuf::c_str() SBuf& SBuf::chop(size_type pos, size_type n) { - if (pos == npos || pos > length() || n == 0) { + if (pos == npos || pos > length()) + pos = length(); + + if (n == npos || (pos+n) > length()) + n = length() - pos; + + // if there will be nothing left, reset the buffer while we can + if (pos == length() || n == 0) { clear(); return *this; } - if (n == npos || (pos+n) > length()) - n = length()-pos; + ++stats.chop; off_ += pos; len_ = n;