https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=195763
Kyle Evans <bsdpo...@kyle-evans.net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bsdpo...@kyle-evans.net --- Comment #1 from Kyle Evans <bsdpo...@kyle-evans.net> --- Created attachment 179126 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=179126&action=edit 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 (st) == match start' to indicate failure, but this isn't right when zero-length 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. 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. -- You are receiving this mail because: You are the assignee for the bug. _______________________________________________ freebsd-bugs@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-bugs To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"