@@ -695,11 +695,11 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
695695 ngx_pool_t * old_pool ;
696696
697697 if (flags & NGX_LUA_RE_MODE_DFA ) {
698- ovecsize = 2 ;
698+ ovecsize = 1 ;
699699 re -> ncaptures = 0 ;
700700
701701 } else {
702- ovecsize = ( re -> ncaptures + 1 ) * 3 ;
702+ ovecsize = re -> ncaptures + 1 ;
703703 }
704704
705705 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,
717717 }
718718
719719 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 );
721721
722722 if (ngx_regex_match_data == NULL ) {
723723 rc = PCRE2_ERROR_NOMEMORY ;
@@ -762,8 +762,8 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
762762 "n %ui, ovecsize %ui" , flags , exec_opts , rc , n , ovecsize );
763763#endif
764764
765- if (!( flags & NGX_LUA_RE_MODE_DFA ) && n > ovecsize / 3 ) {
766- n = ovecsize / 3 ;
765+ if (n > ovecsize ) {
766+ n = ovecsize ;
767767 }
768768
769769 for (i = 0 ; i < n ; i ++ ) {
@@ -796,6 +796,21 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
796796 re -> ncaptures = 0 ;
797797
798798 } 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+ */
799814 ovecsize = (re -> ncaptures + 1 ) * 3 ;
800815 }
801816
0 commit comments