diff --git a/src/main/grep.c b/src/main/grep.c index 32d8d3491d0..7e04eaf9934 100644 --- a/src/main/grep.c +++ b/src/main/grep.c @@ -2385,6 +2385,7 @@ gregexpr_perl(const char *pattern, const char *string, SEXP capturebuf, capturelenbuf; SEXP matchbuf, matchlenbuf; /* buffers for storing multiple matches */ int bufsize = 1024; /* starting size for buffers */ + int slen = (int) strlen(string); PROTECT_INDEX cb, clb, mb, mlb; PROTECT_WITH_INDEX(capturebuf = @@ -2393,9 +2394,9 @@ gregexpr_perl(const char *pattern, const char *string, allocVector(INTSXP, bufsize*capture_count), &clb); PROTECT_WITH_INDEX(matchbuf = allocVector(INTSXP, bufsize), &mb); PROTECT_WITH_INDEX(matchlenbuf = allocVector(INTSXP, bufsize), &mlb); + while (!foundAll) { - int rc, slen = (int) strlen(string); - rc = pcre_exec(re_pcre, re_pe, string, slen, start, 0, ovector, + int rc = pcre_exec(re_pcre, re_pe, string, slen, start, 0, ovector, ovector_size); pcre_exec_error(rc, n); if (rc >= 0) {