From 6fd0701ace1007ed35ec92deefa9b1bb70aad489 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Mon, 7 Oct 2013 22:17:17 -0600 Subject: [PATCH] More SBuf signedness fixes --- src/SBuf.h | 2 +- src/tests/SBufFindTest.cc | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) 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 } -- 2.47.3