summaryrefslogtreecommitdiff
path: root/ext/pcre
diff options
context:
space:
mode:
authorAndrei Zmievski <andrei@php.net>2001-11-10 23:45:00 +0000
committerAndrei Zmievski <andrei@php.net>2001-11-10 23:45:00 +0000
commit3942e2a8bdf87a40949788df6e2a92ba40acf2ab (patch)
treee264230f010e30364b677ed17a19ab590e6b116c /ext/pcre
parent98a7a1ba1f347cb9e2971275bfa4746251ef33c9 (diff)
downloadphp-git-3942e2a8bdf87a40949788df6e2a92ba40acf2ab.tar.gz
Fixed bug #13635.
Diffstat (limited to 'ext/pcre')
-rw-r--r--ext/pcre/php_pcre.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 74caa0f0e9..2fee56b755 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -385,7 +385,8 @@ static void php_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global)
}
/* Calculate the size of the offsets array, and allocate memory for it. */
- num_subpats = pcre_info(re, NULL, NULL) + 1;
+ pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &num_subpats);
+ num_subpats++;
size_offsets = num_subpats * 3;
offsets = (int *)emalloc(size_offsets * sizeof(int));
@@ -434,29 +435,38 @@ static void php_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global)
if (global) { /* global pattern matching */
if (subpats_order_val == PREG_PATTERN_ORDER) {
- /* For each subpattern, insert it into the appropriate array */
- for (i=0; i<count; i++) {
+ /* For each subpattern, insert it into the appropriate array. */
+ for (i = 0; i < count; i++) {
add_next_index_string(match_sets[i], (char *)stringlist[i], 1);
}
- }
- else {
+ /*
+ * If the number of captured subpatterns on this run is
+ * less than the total possible number, pad the result
+ * arrays with empty strings.
+ */
+ if (count < num_subpats) {
+ for (; i < num_subpats; i++) {
+ add_next_index_string(match_sets[i], empty_string, 1);
+ }
+ }
+ } else {
/* Allocate the result set array */
ALLOC_ZVAL(result_set);
array_init(result_set);
INIT_PZVAL(result_set);
/* Add all the subpatterns to it */
- for (i=0; i<count; i++) {
+ for (i = 0; i < count; i++) {
add_next_index_string(result_set, (char *)stringlist[i], 1);
}
/* And add it to the output array */
zend_hash_next_index_insert(Z_ARRVAL_PP(subpats), &result_set,
- sizeof(zval *), NULL);
+ sizeof(zval *), NULL);
}
}
else { /* single pattern matching */
/* For each subpattern, insert it into the subpatterns array. */
- for (i=0; i<count; i++) {
+ for (i = 0; i < count; i++) {
add_next_index_string((*subpats), (char *)stringlist[i], 1);
}
}