------------------------------------------------------------ revno: 13204 revision-id: kinkie@squid-cache.org-20140102230320-1re3sopi3awozt0c parent: kinkie@squid-cache.org-20140102160157-wrmboguocyioqkxf author: Amos Jeffries committer: Francesco Chemolli branch nick: trunk timestamp: Fri 2014-01-03 00:03:20 +0100 message: Fix SBuf::rfind ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: kinkie@squid-cache.org-20140102230320-1re3sopi3awozt0c # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: f7cf508f0f3e3a1fb8a135fd0aa9a7c34d024f43 # timestamp: 2014-01-02 23:53:44 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: kinkie@squid-cache.org-20140102160157-\ # wrmboguocyioqkxf # # Begin patch === modified file 'src/SBuf.cc' --- src/SBuf.cc 2013-12-18 17:53:43 +0000 +++ src/SBuf.cc 2014-01-02 23:03:20 +0000 @@ -630,21 +630,21 @@ ++stats.find; - // on npos input std::string scans from the end of hay - if (endPos == npos || endPos > length()) - endPos = length(); - - // on empty hay std::string returns npos + // needle is bigger than haystack, impossible find if (length() < needle.length()) return npos; - // consistent with std::string: on empty needle return min(endpos,length()) + // if startPos is npos, std::string scans from the end of hay + if (endPos == npos || endPos > length()-needle.length()) + endPos = length()-needle.length(); + + // an empty needle found at the end of the haystack if (needle.length() == 0) return endPos; char *bufBegin = buf(); char *cur = bufBegin+endPos; - char needleBegin = needle[0]; + const char needleBegin = needle[0]; while (cur >= bufBegin) { if (*cur == needleBegin) { if (0 == memcmp(needle.buf(), cur, needle.length())) {