diff options
author | Dmitry Mikhirev | 2015-01-24 14:31:23 +0300 |
---|---|---|
committer | Dmitry Mikhirev | 2015-01-24 14:31:23 +0300 |
commit | 15f22648cd99f392ac5cab6afeec2a0e97b85c6d (patch) | |
tree | 5c94d011d1ae45d066a21d550a85f3f77564ed96 | |
parent | 2b494614096cdb578993b473b1f4ac93cd4dce1a (diff) | |
download | make_pcre-0.3.1.tar.gz make_pcre-0.3.1.tar.bz2 make_pcre-0.3.1.tar.xz make_pcre-0.3.1.zip |
fixed global search hang when zero-length matching foundv0.3.1
-rw-r--r-- | pcre.c | 31 | ||||
-rw-r--r-- | tests.mk | 6 |
2 files changed, 34 insertions, 3 deletions
@@ -389,7 +389,17 @@ static char *match(const char *name, int argc, char **argv) retstr[retlen] = '\0'; /* where to start next search */ - offset = ovec[1]; + if (offset == ovec[1]) { //zero-length match + if (offset < len) { + // continue with one character shift + offset++; + } else { + // stop global search + global = 0; + } + } else { + offset = ovec[1]; + } /* set named make vars to captured substrings */ set_named_vars(re, str, ovec, ncap); @@ -513,7 +523,24 @@ static char *subst(const char *name, int argc, char **argv) rep = NULL; /* where to start next search */ - offset = ovec[1]; + if (offset == ovec[1]) { //zero-length match + if (offset < subjlen) { + // continue with one character shift + s = str_extend(retstr, retlen + 1); + if (s == NULL) { + goto end_subst; + } + retstr = s; + strncpy(retstr + retlen, str + offset, 1); + retlen++; + offset++; + } else { + // stop global search + global = 0; + } + } else { + offset = ovec[1]; + } } } while (global && (ncap != PCRE_ERROR_NOMATCH)); @@ -2,7 +2,7 @@ ifneq ($(findstring 4.,$(MAKE_VERSION)),4.) $(error you need GNU make 4.x to run tests) endif -NUMTESTS = 30 +NUMTESTS = 32 tests := $(foreach num,$(shell seq -f%03g $(NUMTESTS)),test$(num)) load pcre.so @@ -113,6 +113,10 @@ test029 = -z "$(m ^test$,$(subj029))" -a "$(m ^test$,$(subj029),m)" = test test030 = -z "$(m test.test,$(subj029))" -a \ "$(s test.test,passed,$(subj029),s)" = passed +# test zero-length matching +test031 = "$(m x?,aaa,g)" = "" +test032 = "$(s x?,!,abcd,g)" = "!a!b!c!d!" + ### END OF TEST EXPRESSIONS ### test%: |