/* }}} */
/* {{{ static make_subpats_table */
-static char **make_subpats_table(size_t num_subpats, pcre_cache_entry *pce)
+static char **make_subpats_table(uint32_t num_subpats, pcre_cache_entry *pce)
{
uint32_t name_cnt = pce->name_count, name_size, ni = 0;
char *name_table;
uint32_t no_utf_check = 0; /* Execution options */
int count = 0; /* Count of matched subpatterns */
PCRE2_SIZE *offsets; /* Array of subpattern offsets */
- size_t num_subpats; /* Number of captured subpatterns */
- size_t size_offsets; /* Size of the offsets array */
+ uint32_t num_subpats; /* Number of captured subpatterns */
int matched; /* Has anything matched */
uint32_t g_notempty = 0; /* If the match should not be empty */
char **subpat_names; /* Array for named subpatterns */
/* Calculate the size of the offsets array, and allocate memory for it. */
num_subpats = pce->capture_count + 1;
- size_offsets = num_subpats * 3;
/*
* Build a mapping from subpattern numbers to their names. We will
}
#endif
- if (!mdata_used && size_offsets <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
+ if (!mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
match_data = mdata;
} else {
match_data = pcre2_match_data_create_from_pattern(pce->re, gctx);
/* Check for too many substrings condition. */
if (count == 0) {
php_error_docref(NULL, E_NOTICE, "Matched, but too many substrings");
- count = size_offsets/3;
+ count = num_subpats;
}
/* If something has matched */
int count = 0; /* Count of matched subpatterns */
PCRE2_SIZE *offsets; /* Array of subpattern offsets */
char **subpat_names; /* Array for named subpatterns */
- size_t num_subpats; /* Number of captured subpatterns */
- size_t size_offsets; /* Size of the offsets array */
+ uint32_t num_subpats; /* Number of captured subpatterns */
size_t new_len; /* Length of needed storage */
size_t alloc_len; /* Actual allocated length */
size_t match_len; /* Length of the current match */
/* Calculate the size of the offsets array, and allocate memory for it. */
num_subpats = pce->capture_count + 1;
- size_offsets = num_subpats * 3;
/*
* Build a mapping from subpattern numbers to their names. We will
}
#endif
- if (!mdata_used && size_offsets <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
+ if (!mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
match_data = mdata;
} else {
match_data = pcre2_match_data_create_from_pattern(pce->re, gctx);
/* Check for too many substrings condition. */
if (UNEXPECTED(count == 0)) {
php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
- count = size_offsets / 3;
+ count = num_subpats;
}
piece = subject + start_offset;
int count = 0; /* Count of matched subpatterns */
PCRE2_SIZE *offsets; /* Array of subpattern offsets */
char **subpat_names; /* Array for named subpatterns */
- size_t num_subpats; /* Number of captured subpatterns */
- size_t size_offsets; /* Size of the offsets array */
+ uint32_t num_subpats; /* Number of captured subpatterns */
size_t new_len; /* Length of needed storage */
size_t alloc_len; /* Actual allocated length */
PCRE2_SIZE start_offset; /* Where the new search starts */
/* Calculate the size of the offsets array, and allocate memory for it. */
num_subpats = pce->capture_count + 1;
- size_offsets = num_subpats * 3;
/*
* Build a mapping from subpattern numbers to their names. We will
#endif
old_mdata_used = mdata_used;
- if (!old_mdata_used && size_offsets <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
+ if (!old_mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
mdata_used = 1;
match_data = mdata;
} else {
/* Check for too many substrings condition. */
if (count == 0) {
php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
- count = size_offsets / 3;
+ count = num_subpats;
}
piece = subject + start_offset;
zend_long limit_val, zend_long flags)
{
PCRE2_SIZE *offsets; /* Array of subpattern offsets */
- size_t size_offsets; /* Size of the offsets array */
uint32_t no_utf_check = 0; /* Execution options */
int count = 0; /* Count of matched subpatterns */
PCRE2_SIZE start_offset; /* Where the new search starts */
uint32_t no_empty; /* If NO_EMPTY flag is set */
uint32_t delim_capture; /* If delimiters should be captured */
uint32_t offset_capture; /* If offsets should be captured */
+ uint32_t num_subpats; /* Number of captured subpatterns */
zval tmp;
pcre2_match_data *match_data;
array_init(return_value);
/* Calculate the size of the offsets array, and allocate memory for it. */
- size_offsets = (pce->capture_count + 1) * 3;
+ num_subpats = pce->capture_count + 1;
/* Start at the beginning of the string */
start_offset = 0;
}
#endif
- if (!mdata_used && size_offsets <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
+ if (!mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
match_data = mdata;
} else {
match_data = pcre2_match_data_create_from_pattern(pce->re, gctx);
/* Check for too many substrings condition. */
if (count == 0) {
php_error_docref(NULL,E_NOTICE, "Matched, but too many substrings");
- count = size_offsets/3;
+ count = num_subpats;
}
offsets = pcre2_get_ovector_pointer(match_data);
PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return_value, zend_long flags) /* {{{ */
{
zval *entry; /* An entry in the input array */
- size_t size_offsets; /* Size of the offsets array */
+ uint32_t num_subpats; /* Number of captured subpatterns */
int count = 0; /* Count of matched subpatterns */
uint32_t no_utf_check; /* Execution options */
zend_string *string_key;
invert = flags & PREG_GREP_INVERT ? 1 : 0;
/* Calculate the size of the offsets array, and allocate memory for it. */
- size_offsets = (pce->capture_count + 1) * 3;
+ num_subpats = pce->capture_count + 1;
/* Initialize return array */
array_init(return_value);
PCRE_G(error_code) = PHP_PCRE_NO_ERROR;
- if (!mdata_used && size_offsets <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
+ if (!mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE) {
match_data = mdata;
} else {
match_data = pcre2_match_data_create_from_pattern(pce->re, gctx);
/* Check for too many substrings condition. */
if (count == 0) {
php_error_docref(NULL, E_NOTICE, "Matched, but too many substrings");
- count = size_offsets/3;
+ count = num_subpats;
} else if (count < 0 && count != PCRE2_ERROR_NOMATCH) {
pcre_handle_exec_error(count);
zend_string_release(subject_str);