]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
When SBuf chop()s away everything, always clear the buffer.
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 29 Jul 2015 08:54:08 +0000 (01:54 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 29 Jul 2015 08:54:08 +0000 (01:54 -0700)
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.

src/SBuf.cc

index 3789f4b01867a2ac48a83f6f2cc6cc788b29d823..e87df17fda457d80650776e78086576b2536be04 100644 (file)
@@ -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;