Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@WizKid
Created February 15, 2014 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WizKid/9012140 to your computer and use it in GitHub Desktop.
Save WizKid/9012140 to your computer and use it in GitHub Desktop.
diff --git a/hphp/runtime/base/preg.cpp b/hphp/runtime/base/preg.cpp
index e9e637b..fcb0cbf 100644
--- a/hphp/runtime/base/preg.cpp
+++ b/hphp/runtime/base/preg.cpp
@@ -1064,6 +1064,12 @@ static Variant php_pcre_replace(const String& pattern, const String& subject,
VMExecutionContext::InvokePseudoMain);
eval_result = v;
+ // Make sure that we have enough space in result
+ if (eval_result.size() > alloc_len - result_len) {
+ alloc_len = 1 + result_len + 2 * eval_result.size();
+ result = (char *)realloc(result, alloc_len);
+ }
+
memcpy(result + result_len, eval_result.data(), eval_result.size());
result_len += eval_result.size();
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment