Date: Fri, 20 Jan 2017 06:27:46 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 195763] bsdgrep, empty matches and -o Message-ID: <bug-195763-8-8o74CUdAh2@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-195763-8@https.bugs.freebsd.org/bugzilla/> References: <bug-195763-8@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D195763 Kyle Evans <bsdports@kyle-evans.net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bsdports@kyle-evans.net --- Comment #1 from Kyle Evans <bsdports@kyle-evans.net> --- 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.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-195763-8-8o74CUdAh2>