From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2323 invoked by alias); 11 Apr 2008 12:45:16 -0000 Received: (qmail 31103 invoked by uid 48); 11 Apr 2008 12:44:30 -0000 Date: Fri, 11 Apr 2008 12:45:00 -0000 From: "bonzini at gnu dot org" To: glibc-bugs-regex@sources.redhat.com Message-ID: <20080411124430.6395.bonzini@gnu.org> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug regex/6395] New: regex ^$ is not detected as anchored X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-regex-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-regex-owner@sourceware.org X-SW-Source: 2008-04/txt/msg00000.txt.bz2 Regex matching has an optimization where only one match is tried for a regex anchored to the beginning of the buffer. While other anchors are resolved with the fastmap, this one allows further optimization and is special cased. However, because of a bug in create_cd_newstate, ^$ would be mistakenly treated as a non-anchoring match, and re_search_internal would try matching it at every position. In fact, the bug is (almost) fixed by this hunk: @@ -1682,8 +1680,6 @@ create_cd_newstate (const re_dfa_t *dfa, newstate->halt = 1; else if (type == OP_BACK_REF) newstate->has_backref = 1; - else if (type == ANCHOR) - constraint = node->opr.ctx_type; if (constraint) { However, some complications in building the NFA prevent this from fixing the problem. Therefore, this patch cleans up the handling of anchors so that tests on type == ANCHOR are not necessary anymore. When creating the NFA (calc_first), I move the opr.ctx_type to the constraint field of re_token_t, and then I always look at it unconditionally, without special-casing ANCHORs. This also allows some simplification of duplicate_node_closure. -- Summary: regex ^$ is not detected as anchored Product: glibc Version: unspecified Status: NEW Severity: enhancement Priority: P2 Component: regex AssignedTo: bonzini at gnu dot org ReportedBy: bonzini at gnu dot org CC: glibc-bugs-regex at sources dot redhat dot com,glibc- bugs at sources dot redhat dot com http://sourceware.org/bugzilla/show_bug.cgi?id=6395 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.