summaryrefslogtreecommitdiff
path: root/ext/mbstring/mbstring.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2018-06-11 17:43:29 +0200
committerAnatol Belski <ab@php.net>2018-06-11 17:44:34 +0200
commita34ba6f30c2dbc71127be01a47a4f44e1d5e678d (patch)
tree61ccc669d84dfaf5585cae122cf5f214145193ef /ext/mbstring/mbstring.c
parentdc99a13fac8168d3812df3996d0cce9c8b45f518 (diff)
downloadphp-git-a34ba6f30c2dbc71127be01a47a4f44e1d5e678d.tar.gz
Fix mbstring fallback when --disable-mbregex used
Diffstat (limited to 'ext/mbstring/mbstring.c')
-rw-r--r--ext/mbstring/mbstring.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index b17b8f8f8e..2c2a4824cc 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -1045,13 +1045,15 @@ static void _php_mb_free_regex(void *opaque)
/* {{{ _php_mb_compile_regex */
static void *_php_mb_compile_regex(const char *pattern)
{
- pcre *retval;
- const char *err_str;
- int err_offset;
+ pcre2_code *retval;
+ PCRE2_SIZE err_offset;
+ int errnum;
- if (!(retval = pcre_compile(pattern,
- PCRE_CASELESS, &err_str, &err_offset, NULL))) {
- php_error_docref(NULL, E_WARNING, "%s (offset=%d): %s", pattern, err_offset, err_str);
+ if (!(retval = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
+ PCRE2_CASELESS, &errnum, &err_offset, php_pcre_cctx()))) {
+ PCRE2_UCHAR err_str[256];
+ pcre2_get_error_message(errnum, err_str, sizeof(err_str));
+ php_error_docref(NULL, E_WARNING, "%s (offset=%zu): %s", pattern, err_offset, err_str);
}
return retval;
}
@@ -1060,15 +1062,25 @@ static void *_php_mb_compile_regex(const char *pattern)
/* {{{ _php_mb_match_regex */
static int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
{
- return pcre_exec((pcre *)opaque, NULL, str, (int)str_len, 0,
- 0, NULL, 0) >= 0;
+ int res;
+
+ pcre2_match_data *match_data = php_pcre_create_match_data(0, opaque);
+ if (NULL == match_data) {
+ pcre2_code_free(opaque);
+ php_error_docref(NULL, E_WARNING, "Cannot allocate match data");
+ return FAILURE;
+ }
+ res = pcre2_match(opaque, (PCRE2_SPTR)str, str_len, 0, 0, match_data, php_pcre_mctx());
+ php_pcre_free_match_data(match_data);
+
+ return res;
}
/* }}} */
/* {{{ _php_mb_free_regex */
static void _php_mb_free_regex(void *opaque)
{
- pcre_free(opaque);
+ pcre2_code_free(opaque);
}
/* }}} */
#endif