From owner-freebsd-bugs@freebsd.org Fri Jan 20 06:27:46 2017 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A2157CB9DF3 for ; Fri, 20 Jan 2017 06:27:46 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 774B61689 for ; Fri, 20 Jan 2017 06:27:46 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id v0K6Rkvf070538 for ; Fri, 20 Jan 2017 06:27:46 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 195763] bsdgrep, empty matches and -o Date: Fri, 20 Jan 2017 06:27:46 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 10.1-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: bsdports@kyle-evans.net X-Bugzilla-Status: Open X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc attachments.created Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jan 2017 06:27:46 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D195763 Kyle Evans changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bsdports@kyle-evans.net --- Comment #1 from Kyle Evans --- Created attachment 179126 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D179126&action= =3Dedit Proposed patch to address zero length match issues with bsdgrep Hi, Attached is a patch that seems to fix the behavior of zero-length matches. procline() was previously using something along the lines of 'next start (s= t) =3D=3D match start' to indicate failure, but this isn't right when zero-len= gth matches are possible. Therefore, we make a couple of critical changes: 1.) Keep track of the number of total matches we came across 2.) Don't add zero-length matches to our output 3.) If we had any matches, keep going. If st didn't advance beyond our first match, we only had zero-length matches To fix the empty expression case, I changed the argv pattern matching bits = in main() to actually skip invalid expressions.=20 Your test expressions now yield the following results: root@ghost:/usr/obj/usr/src/usr.bin/grep# echo '01:1:01' | ./bsdgrep -Eo '(^|:)0*' 0 : :0 # Good root@ghost:/usr/obj/usr/src/usr.bin/grep# echo '1:1:01' | ./bsdgrep -Eo '(^|:)0*' : :0 # Better root@ghost:/usr/obj/usr/src/usr.bin/grep# echo 'bla bla' | ./bsdgrep -Eo '[[:alnum:]]*' bla bla # Good root@ghost:/usr/obj/usr/src/usr.bin/grep# printf 'bla\nbla\n' | ./bsdgrep -= Eo '' # Good I think this approach is mostly right, except for perhaps the bits in grep.c:main() to make sure we don't recognize invalid patterns as input patterns. --=20 You are receiving this mail because: You are the assignee for the bug.=