From: Amos Jeffries Date: Tue, 8 Oct 2013 04:17:17 +0000 (-0600) Subject: More SBuf signedness fixes X-Git-Tag: SQUID_3_5_0_1~603 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6fd0701ace1007ed35ec92deefa9b1bb70aad489;p=thirdparty%2Fsquid.git More SBuf signedness fixes --- diff --git a/src/SBuf.h b/src/SBuf.h index cf07a3015d..5f914605a8 100644 --- a/src/SBuf.h +++ b/src/SBuf.h @@ -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); } diff --git a/src/tests/SBufFindTest.cc b/src/tests/SBufFindTest.cc index d07f5b0e35..5e436f5d21 100644 --- a/src/tests/SBufFindTest.cc +++ b/src/tests/SBufFindTest.cc @@ -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(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(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 }