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
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();
}
}
+TEST(FBString, findWithNpos) {
+ fbstring fbstr("localhost:80");
+ EXPECT_EQ(fbstring::npos, fbstr.find(":", fbstring::npos));
+}
+
TEST(FBString, testHash) {
fbstring a;
fbstring b;