Commit 3a5767e7 authored by Jeremy Lilley's avatar Jeremy Lilley Committed by Jordan DeLong

Fix push_back() to shared fbstring bug.

Summary:
The following asserts:
fbstring str(1337, 'f');
fbstring cp = str;
cp.push_back('f');

This is problematic since ml_.capacity() != capacity() inside fbstring_core
for shared strings, which causes us not to un-share prior to push_back.

Test Plan: Existing tests, add unittest case.

Reviewed By: tudorb@fb.com

FB internal diff: D580267
parent 0010b30e
...@@ -626,7 +626,7 @@ public: ...@@ -626,7 +626,7 @@ public:
} else { } else {
sz = ml_.size_; sz = ml_.size_;
newSz = ml_.size_ + delta; newSz = ml_.size_ + delta;
if (newSz > ml_.capacity()) { if (newSz > capacity()) {
reserve(newSz); reserve(newSz);
} }
} }
...@@ -653,7 +653,7 @@ public: ...@@ -653,7 +653,7 @@ public:
reserve(maxSmallSize * 2); reserve(maxSmallSize * 2);
} else { } else {
sz = ml_.size_; sz = ml_.size_;
cp = ml_.capacity(); cp = capacity(); // != ml_.capacity() for isShared()
if (sz == cp) reserve(cp * 3 / 2); if (sz == cp) reserve(cp * 3 / 2);
} }
assert(capacity() >= sz + 1); assert(capacity() >= sz + 1);
......
...@@ -981,6 +981,18 @@ TEST(FBString, testFixedBugs) { ...@@ -981,6 +981,18 @@ TEST(FBString, testFixedBugs) {
cp.push_back('?'); cp.push_back('?');
} }
} }
{ // D580267
{
fbstring str(1337, 'f');
fbstring cp = str;
cp.push_back('f');
}
{
fbstring str(1337, 'f');
fbstring cp = str;
cp += "bb";
}
}
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
......
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