]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
More SBuf signedness fixes
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 8 Oct 2013 04:17:17 +0000 (22:17 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 8 Oct 2013 04:17:17 +0000 (22:17 -0600)
src/SBuf.h
src/tests/SBufFindTest.cc

index cf07a3015d22392c2c78853b9700accf492b8f75..5f914605a816b1c2b0e8a859f875f9c9efabe191 100644 (file)
@@ -417,7 +417,7 @@ public:
      * \throw SBufTooBigException if the user tries to allocate too big a SBuf
      */
     void reserveSpace(size_type minSpace) {
-        Must(minSpace < maxSize);
+        Must(minSpace <= maxSize);
         Must(length() <= maxSize - minSpace);
         reserveCapacity(length()+minSpace);
     }
index d07f5b0e3501fc0cdd4478c906c2f5eb951b5eb7..5e436f5d210474d6c84aa69212192fe8bcb31284 100644 (file)
@@ -166,9 +166,6 @@ SBufFindTest::resultsMatch() const
     if (theFindString == std::string::npos && theFindSBuf == SBuf::npos)
         return true; // both npos
 
-    if (theFindSBuf < 0) // should not happen, treat as error
-        return false;
-
     // now safe to cast a non-negative SBuf result
     return theFindString == static_cast<std::string::size_type>(theFindSBuf);
 }
@@ -267,23 +264,21 @@ SBufFindTest::posKey() const
     if (thePos == SBuf::npos)
         return ",npos";
 
-    if (thePos < 0)
-        return ",posN"; // negative
-
-    // we know Pos is not negative or special; avoid signed/unsigned warnings
-    const std::string::size_type pos =
-        static_cast<std::string::size_type>(thePos);
-
-    if (pos < theBareNeedlePos)
+    if (thePos < theBareNeedlePos)
         return ",posL"; // to the Left of the needle
-    if (pos == theBareNeedlePos)
+
+    if (thePos == theBareNeedlePos)
         return ",posB"; // Beginning of the needle
-    if (pos < theBareNeedlePos + theStringNeedle.length())
+
+    if (thePos < theBareNeedlePos + theStringNeedle.length())
         return ",posM"; // in the Middle of the needle
-    if (pos == theBareNeedlePos + theStringNeedle.length())
+
+    if (thePos == theBareNeedlePos + theStringNeedle.length())
         return ",posE"; // at the End of the needle
-    if (pos < theStringHay.length())
+
+    if (thePos < theStringHay.length())
         return ",posR"; // to the Right of the needle
+
     return ",posP"; // past the hay
 }