/* the string was already proved to be valid UTF-8 */
options |= PCRE2_NO_UTF_CHECK;
- /* Check for too many substrings condition. */
- if (count == 0) {
- php_error_docref(NULL, E_NOTICE, "Matched, but too many substrings");
- count = num_subpats;
- }
-
/* If something has matched */
- if (count > 0) {
+ if (count >= 0) {
+ /* Check for too many substrings condition. */
+ if (UNEXPECTED(count == 0)) {
+ php_error_docref(NULL, E_NOTICE, "Matched, but too many substrings");
+ count = num_subpats;
+ }
+
matched++;
offsets = pcre2_get_ovector_pointer(match_data);
/* the string was already proved to be valid UTF-8 */
options |= PCRE2_NO_UTF_CHECK;
- /* Check for too many substrings condition. */
- if (UNEXPECTED(count == 0)) {
- php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
- count = num_subpats;
- }
-
piece = subject + start_offset;
- offsets = pcre2_get_ovector_pointer(match_data);
-
- if (count > 0 && (offsets[1] >= offsets[0]) && limit > 0) {
+ if (count >= 0 && limit > 0) {
zend_bool simple_string = 1;
+ /* Check for too many substrings condition. */
+ if (UNEXPECTED(count == 0)) {
+ php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
+ count = num_subpats;
+ }
+
+ offsets = pcre2_get_ovector_pointer(match_data);
+
+ if (UNEXPECTED(offsets[1] < offsets[0])) {
+ PCRE_G(error_code) = PHP_PCRE_INTERNAL_ERROR;
+ if (result) {
+ zend_string_release_ex(result, 0);
+ result = NULL;
+ }
+ break;
+ }
+
if (replace_count) {
++*replace_count;
}
/* the string was already proved to be valid UTF-8 */
options |= PCRE2_NO_UTF_CHECK;
- /* Check for too many substrings condition. */
- if (count == 0) {
- php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
- count = num_subpats;
- }
-
piece = subject + start_offset;
- offsets = pcre2_get_ovector_pointer(match_data);
mark = pcre2_get_mark(match_data);
- /* if (EXPECTED(count > 0 && (limit == -1 || limit > 0))) */
- if (count > 0 && (offsets[1] >= offsets[0]) && limit) {
+ if (count >= 0 && limit) {
+ /* Check for too many substrings condition. */
+ if (UNEXPECTED(count == 0)) {
+ php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
+ count = num_subpats;
+ }
+
+ offsets = pcre2_get_ovector_pointer(match_data);
+
+ if (UNEXPECTED(offsets[1] < offsets[0])) {
+ PCRE_G(error_code) = PHP_PCRE_INTERNAL_ERROR;
+ if (result) {
+ zend_string_release_ex(result, 0);
+ result = NULL;
+ }
+ break;
+ }
+
if (replace_count) {
++*replace_count;
}
/* the string was already proved to be valid UTF-8 */
options |= PCRE2_NO_UTF_CHECK;
- /* Check for too many substrings condition. */
- if (count == 0) {
- php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
- count = num_subpats;
- }
+ /* If something matched */
+ if (count >= 0) {
+ /* Check for too many substrings condition. */
+ if (UNEXPECTED(count == 0)) {
+ php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
+ count = num_subpats;
+ }
- offsets = pcre2_get_ovector_pointer(match_data);
+ offsets = pcre2_get_ovector_pointer(match_data);
+
+ if (UNEXPECTED(offsets[1] < offsets[0])) {
+ PCRE_G(error_code) = PHP_PCRE_INTERNAL_ERROR;
+ break;
+ }
- /* If something matched */
- if (count > 0 && (offsets[1] >= offsets[0])) {
if (!no_empty || &ZSTR_VAL(subject_str)[offsets[0]] != last_match) {
if (offset_capture) {
count = pcre2_match(pce->re, (PCRE2_SPTR)ZSTR_VAL(subject_str), ZSTR_LEN(subject_str), 0,
options, match_data, mctx);
- /* Check for too many substrings condition. */
- if (count == 0) {
- php_error_docref(NULL, E_NOTICE, "Matched, but too many substrings");
- count = num_subpats;
- } else if (count < 0 && count != PCRE2_ERROR_NOMATCH) {
- pcre_handle_exec_error(count);
- zend_string_release_ex(subject_str, 0);
- break;
- }
-
/* If the entry fits our requirements */
- if ((count > 0 && !invert) || (count == PCRE2_ERROR_NOMATCH && invert)) {
+ if ((count >= 0 && !invert) || (count == PCRE2_ERROR_NOMATCH && invert)) {
+ /* Check for too many substrings condition. */
+ if (UNEXPECTED(count == 0)) {
+ php_error_docref(NULL, E_NOTICE, "Matched, but too many substrings");
+ count = num_subpats;
+ }
Z_TRY_ADDREF_P(entry);
/* Add to return array */
} else {
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
}
+ } else if (count < 0 && count != PCRE2_ERROR_NOMATCH) {
+ pcre_handle_exec_error(count);
+ zend_string_release_ex(subject_str, 0);
+ break;
}
zend_string_release_ex(subject_str, 0);