# HG changeset patch # User Thomas Weber # Date 1222028869 -7200 # Node ID cdcbbbccc0caa872c57f39fc206866d4c95a9e40 # Parent 2be5ab236e204fcb7484ee239c0faa52083ceb90 Increase pcre's match_limit for difficult regexps diff -r 2be5ab236e20 -r cdcbbbccc0ca src/DLD-FUNCTIONS/regexp.cc --- a/src/DLD-FUNCTIONS/regexp.cc Fri Sep 19 21:23:00 2008 +0200 +++ b/src/DLD-FUNCTIONS/regexp.cc Sun Sep 21 22:27:49 2008 +0200 @@ -298,9 +298,27 @@ (idx ? PCRE_NOTBOL : 0), ovector, (subpatterns+1)*3); + if (matches == PCRE_ERROR_MATCHLIMIT) + { + // try harder; start with default value for MATCH_LIMIT and increase it + warning("Your pattern caused PCRE to hit its MATCH_LIMIT.\nTrying harder now, but this will be slow."); + pcre_extra pe; + pcre_config(PCRE_CONFIG_MATCH_LIMIT, static_cast (&pe.match_limit)); + pe.flags = PCRE_EXTRA_MATCH_LIMIT; + + while (matches == PCRE_ERROR_MATCHLIMIT) + { + pe.match_limit *= 10; + matches = pcre_exec(re, &pe, buffer.c_str(), + buffer.length(), idx, + (idx ? PCRE_NOTBOL : 0), + ovector, (subpatterns+1)*3); + } + } + if (matches < 0 && matches != PCRE_ERROR_NOMATCH) { - error ("%s: internal error calling pcre_exec", nm.c_str()); + error ("%s: internal error calling pcre_exec\nError code from pcre_exec is %i", nm.c_str(), matches); pcre_free(re); return 0; }