summaryrefslogtreecommitdiff
path: root/pcre_compile.c
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2009-03-20 11:22:42 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2009-03-20 11:22:42 +0000
commit180f0ae93baecec24df25f671865f1238b9563cd (patch)
tree41d222f9207d4d7577f2dda9fa83f6d728e3d719 /pcre_compile.c
parent42895029897bc56f99d0d9acd546a98c45961a5a (diff)
downloadpcre-180f0ae93baecec24df25f671865f1238b9563cd.tar.gz
Fix looping bug by recognizing that a conditional with only one branch may
match an empty string. git-svn-id: svn://vcs.exim.org/pcre/code/trunk@395 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcre_compile.c')
-rw-r--r--pcre_compile.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/pcre_compile.c b/pcre_compile.c
index cfd803d..bac03da 100644
--- a/pcre_compile.c
+++ b/pcre_compile.c
@@ -1663,18 +1663,26 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE
{
BOOL empty_branch;
if (GET(code, 1) == 0) return TRUE; /* Hit unclosed bracket */
-
- /* Scan a closed bracket */
-
- empty_branch = FALSE;
- do
- {
- if (!empty_branch && could_be_empty_branch(code, endcode, utf8))
- empty_branch = TRUE;
+
+ /* If a conditional group has only one branch, there is a second, implied,
+ empty branch, so just skip over the conditional, because it could be empty.
+ Otherwise, scan the individual branches of the group. */
+
+ if (c == OP_COND && code[GET(code, 1)] != OP_ALT)
code += GET(code, 1);
+ else
+ {
+ empty_branch = FALSE;
+ do
+ {
+ if (!empty_branch && could_be_empty_branch(code, endcode, utf8))
+ empty_branch = TRUE;
+ code += GET(code, 1);
+ }
+ while (*code == OP_ALT);
+ if (!empty_branch) return FALSE; /* All branches are non-empty */
}
- while (*code == OP_ALT);
- if (!empty_branch) return FALSE; /* All branches are non-empty */
+
c = *code;
continue;
}