[Bug 195763] bsdgrep, empty matches and -o
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Fri Jan 20 06:27:46 UTC 2017
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=195763
Kyle Evans <bsdports at kyle-evans.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bsdports at kyle-evans.net
--- Comment #1 from Kyle Evans <bsdports at 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 at ghost:/usr/obj/usr/src/usr.bin/grep# echo '01:1:01' | ./bsdgrep -Eo
'(^|:)0*'
0
:
:0
# Good
root at ghost:/usr/obj/usr/src/usr.bin/grep# echo '1:1:01' | ./bsdgrep -Eo
'(^|:)0*'
:
:0
# Better
root at ghost:/usr/obj/usr/src/usr.bin/grep# echo 'bla bla' | ./bsdgrep -Eo
'[[:alnum:]]*'
bla
bla
# Good
root at 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.
More information about the freebsd-bugs
mailing list