diff options
author | Moriyoshi Koizumi <moriyoshi@php.net> | 2003-09-26 17:43:39 +0000 |
---|---|---|
committer | Moriyoshi Koizumi <moriyoshi@php.net> | 2003-09-26 17:43:39 +0000 |
commit | 83609e08744e2cbad1fc742e36f8086809bbf499 (patch) | |
tree | 147c58977b6b331563ab553d5ebe0f89a152b3af /ext/mbstring/php_mbregex.c | |
parent | 7e4a886971ee6827bfccdbaf66647d2fe839ef4a (diff) | |
download | php-git-83609e08744e2cbad1fc742e36f8086809bbf499.tar.gz |
Repatch fixes for the problem that was reported at php-dev@php.gr.jp (#884)
Diffstat (limited to 'ext/mbstring/php_mbregex.c')
-rw-r--r-- | ext/mbstring/php_mbregex.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index b8fc3c27d1..f945d8c727 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -516,6 +516,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int op smart_str *pbuf; int i, err, eval, n; UChar *pos; + UChar *string_lim; char *description = NULL; char pat_buf[2]; @@ -579,9 +580,10 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int op /* do the actual work */ err = 0; pos = string; + string_lim = (UChar*)(string + string_len); regs = php_mb_regex_region_new(); while (err >= 0) { - err = php_mb_regex_search(re, (UChar *)string, (UChar *)(string + string_len), pos, (UChar *)(string + string_len), regs, 0); + err = php_mb_regex_search(re, (UChar *)string, (UChar *)string_lim, pos, (UChar *)string_lim, regs, 0); if (err <= -2) { UChar err_str[REG_MAX_ERROR_MESSAGE_LEN]; php_mb_regex_error_code_to_str(err_str, err); @@ -636,16 +638,15 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int op if ((size_t)(pos - (UChar *)string) < n) { pos = string + n; } else { - smart_str_appendl(&out_buf, pos, 1); + if (pos < string_lim) { + smart_str_appendl(&out_buf, pos, 1); + } pos++; } } else { /* nomatch */ /* stick that last bit of string on our output */ - int l = (UChar *)(string + string_len) - pos; - if (l > 0) { - smart_str_appendl(&out_buf, pos, l); - } else { - out_buf.len += l; + if (string_lim - pos > 0) { + smart_str_appendl(&out_buf, pos, string_lim - pos); } } php_mb_regex_region_free(regs, 0); |