Commit b3cd8a1b authored by Rajat Goel's avatar Rajat Goel Committed by Sara Golemon

Issue with find and npos

Summary:
I dont know whats the expected behavior but for std::string it seems
to work.

@override-unit-failures

Test Plan:
unit-tests

[ RUN      ] FBString.findWithNpos
folly/test/FBStringTest.cpp:1147: Failure
Value of: fbstr.find(":", fbstring::npos)
Actual: 9
Expected: fbstring::npos
Which is: 18446744073709551615

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1012870
parent b604632b
......@@ -1794,7 +1794,9 @@ public:
const size_type nsize) const {
if (!nsize) return pos;
auto const size = this->size();
if (nsize + pos > size) return npos;
// nsize + pos can overflow (eg pos == npos), guard against that by checking
// that nsize + pos does not wrap around.
if (nsize + pos > size || nsize + pos < pos) return npos;
// Don't use std::search, use a Boyer-Moore-like trick by comparing
// the last characters first
auto const haystack = data();
......
......@@ -1139,6 +1139,11 @@ TEST(FBString, testFixedBugs) {
}
}
TEST(FBString, findWithNpos) {
fbstring fbstr("localhost:80");
EXPECT_EQ(fbstring::npos, fbstr.find(":", fbstring::npos));
}
TEST(FBString, testHash) {
fbstring a;
fbstring b;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment