From: Alex Rousskov Date: Wed, 29 Jul 2015 08:54:08 +0000 (-0700) Subject: When SBuf chop()s away everything, always clear the buffer. X-Git-Tag: SQUID_3_5_7~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66a7cb18ad835b0a2411298db1b9d6dcf7d4ae18;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 3789f4b018..e87df17fda 100644 --- a/src/SBuf.cc +++ b/src/SBuf.cc @@ -541,12 +541,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;