@@ -695,11 +695,11 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
695
695
ngx_pool_t * old_pool ;
696
696
697
697
if (flags & NGX_LUA_RE_MODE_DFA ) {
698
- ovecsize = 2 ;
698
+ ovecsize = 1 ;
699
699
re -> ncaptures = 0 ;
700
700
701
701
} else {
702
- ovecsize = ( re -> ncaptures + 1 ) * 3 ;
702
+ ovecsize = re -> ncaptures + 1 ;
703
703
}
704
704
705
705
old_pool = ngx_stream_lua_pcre_malloc_init (NULL );
@@ -717,7 +717,7 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
717
717
}
718
718
719
719
ngx_regex_match_data_size = ovecsize ;
720
- ngx_regex_match_data = pcre2_match_data_create (ovecsize / 3 , NULL );
720
+ ngx_regex_match_data = pcre2_match_data_create (ovecsize , NULL );
721
721
722
722
if (ngx_regex_match_data == NULL ) {
723
723
rc = PCRE2_ERROR_NOMEMORY ;
@@ -762,8 +762,8 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
762
762
"n %ui, ovecsize %ui" , flags , exec_opts , rc , n , ovecsize );
763
763
#endif
764
764
765
- if (!( flags & NGX_LUA_RE_MODE_DFA ) && n > ovecsize / 3 ) {
766
- n = ovecsize / 3 ;
765
+ if (n > ovecsize ) {
766
+ n = ovecsize ;
767
767
}
768
768
769
769
for (i = 0 ; i < n ; i ++ ) {
@@ -796,6 +796,21 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
796
796
re -> ncaptures = 0 ;
797
797
798
798
} else {
799
+ /* How pcre_exec() returns captured substrings
800
+ * The first two-thirds of the vector is used to pass back captured
801
+ * substrings, each substring using a pair of integers. The remaining
802
+ * third of the vector is used as workspace by pcre_exec() while
803
+ * matching capturing subpatterns, and is not available for passing
804
+ * back information. The number passed in ovecsize should always be a
805
+ * multiple of three. If it is not, it is rounded down.
806
+ *
807
+ * When a match is successful, information about captured substrings is
808
+ * returned in pairs of integers, starting at the beginning of ovector,
809
+ * and continuing up to two-thirds of its length at the most. The first
810
+ * element of each pair is set to the byte offset of the first character
811
+ * in a substring, and the second is set to the byte offset of the first
812
+ * character after the end of a substring.
813
+ */
799
814
ovecsize = (re -> ncaptures + 1 ) * 3 ;
800
815
}
801
816
0 commit comments