From: Peter Griess Date: Wed, 16 Oct 2013 19:43:02 +0000 (-0500) Subject: Fix broken clause11_21_4_6_6 test in Apple Clang. X-Git-Tag: v0.22.0~790 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1c3d7f2a87dbac3f2a587b7c870a1b6ac78a3ced;p=folly.git Fix broken clause11_21_4_6_6 test in Apple Clang. Summary: - Prior to this fix, the test relied upon begin() being evaluated after the fbstring constructor (even thoug the order of evaluation of function arguments is un-defined). When this assumption was violated, begin() ended up with an iterator that was invalid since it points to data internal to fbstring, and the fbstring copy constructor can end up triggering re-allocation in the source. Test Plan: - fbconfig -r folly && fbmake runtests - ./configure && make check on Ubuntu/FC/Mac Reviewed By: andrei.alexandrescu@fb.com FB internal diff: D1014093 --- diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index 3efd652e..4f0aa89a 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -526,10 +526,11 @@ template void clause11_21_4_6_6(String & test) { random(0, maxString), random('a', 'z')); pos = random(0, test.size()); if (avoidAliasing) { + auto newString = String(test); test.replace( test.begin() + pos, test.begin() + pos + random(0, test.size() - pos), - String(test)); + newString); } else { test.replace( test.begin() + pos, @@ -538,10 +539,11 @@ template void clause11_21_4_6_6(String & test) { } pos = random(0, test.size()); if (avoidAliasing) { + auto newString = String(test); test.replace( test.begin() + pos, test.begin() + pos + random(0, test.size() - pos), - String(test).c_str(), + newString.c_str(), test.size() - random(0, test.size())); } else { test.replace(