pollita Mon Feb 23 15:06:02 2004 EDT Modified files: /php-src/ext/standard string.c Log: Bugfix #27276: When using str_replace to expand a string, count occurances of needle in haystack to avoid massive overallocation http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.408&r2=1.409&ty=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.408 php-src/ext/standard/string.c:1.409 --- php-src/ext/standard/string.c:1.408 Thu Jan 8 03:17:34 2004 +++ php-src/ext/standard/string.c Mon Feb 23 15:06:01 2004 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.408 2004/01/08 08:17:34 andi Exp $ */ +/* $Id: string.c,v 1.409 2004/02/23 20:06:01 pollita Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3001,7 +3001,14 @@ if (str_len < needle_len) { new_str = emalloc(length + 1); } else { - new_str = safe_emalloc((length / needle_len + 1), str_len, 0); + int count = 0; + char *o = haystack, *endp = haystack + length; + + while ((o = php_memnstr(o, needle, needle_len, endp))) { + o += needle_len; + count++; + } + new_str = safe_emalloc(count, str_len - needle_len, length + 1); } e = s = new_str;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php