freebsd-dev/contrib
Kyle Evans 3e2d96ac97 grep: fix -A handling in conjunction with -m match limitation
The basic issue here is that grep, when given -m 1, would stop all
line processing once it hit the match count and exit immediately.  The
problem with exiting immediately is that -A processing only happens when
subsequent lines are processed and do not match.

The fix here is relatively easy; when bsdgrep matches a line, it resets
the 'tail' of the matching context to the value supplied to -A and
dumps anything that's been queued up for -B. After the current line has
been printed and tail is reset, we check our mcount and do what's
needed. Therefore, at the time that we decide we're doing nothing, we
know that 'tail' of the context is correct and we can simply continue
on if there's still more to pick up.

With this change, we still bail out immediately if there's been no -A
flag. If -A was supplied, we signal that we should continue on. However,
subsequent lines will not even bothere to try and process the line.  We
have reached the match count, so even if the next line would match then
we must process it if it hadn't. Thus, the loop in procfile() can
short-circuit and just process the line as a non-match until
procmatches() indicates that it's safe to stop.

A test has been added to reflect both that we should be picking up the
next line and that the next line should be considered a non-match even
if it should have been.

PR:		253350
MFC-after:	3 days
2021-02-08 12:41:22 -06:00
..
apr Update apr to 1.7.0. See contrib/apr/CHANGES for a summary of changes. 2020-05-31 22:12:56 +00:00
apr-util Update apr-util to 1.6.1. See contrib/apr-util/CHANGES for a summary of 2020-06-01 10:14:45 +00:00
atf Import atf 0.22 snapshot ca73d08c3fc1ecffc1f1c97458c31ab82c12bb01 2021-02-04 15:03:05 +00:00
bc Merge commit '47a52dc4d48f259ab7d9f9ba6b65f4f2331a22dc' 2021-01-31 21:07:42 +01:00
bearssl
blacklist blacklistd.conf.5: typo/grammar fixes 2020-05-19 00:15:19 +00:00
bmake Merge bmake-20210110 2021-01-13 22:21:37 -08:00
bsnmp Revert "bsnmpclient(3): make it thread-safe" 2020-12-29 19:55:05 +00:00
byacc byacc: fix UBSan signed shift range error 2020-09-23 12:54:42 +00:00
bzip2
capsicum-test Revert r358001 in favor of r366509 2020-10-07 07:55:55 +00:00
com_err
cortex-strings
dialog
diff Fix macro-redefined warning in gnu/diff for fputc_unlocked 2021-01-19 21:23:25 +00:00
dma
ee ee(1): Whitespace cleanup 2020-12-10 10:58:30 +00:00
elftoolchain readelf: do not trucate section name with -W 2021-02-03 16:24:22 -05:00
expat MFV r355071: libbsdxml (expat) 2.2.9. 2019-11-25 07:48:16 +00:00
file Revert r362261, "Re-apply r333944 to unbreak ports" 2020-06-29 13:30:48 +00:00
flex [flex] Fix compilation issue under mips-gcc-6.4 2020-07-14 05:00:08 +00:00
gdtoa
googletest Re-enable disabled googletest-port-test tests after r363820 2020-08-04 02:20:15 +00:00
hyperv/tools
ipfilter Simplify FreeBSD check. 2021-02-05 18:39:38 -08:00
jemalloc Fix abort in jemalloc extent coalescing. 2020-12-18 10:09:21 +00:00
kyua Revert r359385-r359387 2020-03-29 02:40:03 +00:00
ldns Fix crash in drill(1) when IP has two subsequent dots 2020-06-22 23:13:14 +00:00
ldns-host
less MFV r366990: less v563. 2020-10-24 15:58:42 +00:00
lib9p Import lib9p 9d5aee77bcc1bf0e79b0a3bfefff5fdf2146283c. 2020-10-03 18:52:54 +00:00
libarchive contrib/libarchive: Import libarchive 3.5.1 2020-12-28 00:34:06 +01:00
libbegemot
libc-pwcache pwcache.3: Explicitly document OOM condition 2020-05-05 17:55:45 +00:00
libc-vis
libcxxrt Make vector-related functions in libcxxrt's demangler static 2020-11-04 17:51:09 +00:00
libdivsufsort
libedit Fix arm and aarch64 builds of libedit after r352275 2019-09-14 21:49:42 +00:00
libevent
libexecinfo Pull in fix from upstream NetBSD rev. 1.5: 2020-09-21 16:43:38 +00:00
libpcap MFV r355890: 2019-12-21 21:05:53 +00:00
libucl
libxo Import libxo-1.4.0: 2020-01-25 21:16:45 +00:00
llvm-project Fix clang assertion when compiling the devel/onetbb port 2021-01-26 17:51:25 +01:00
lua contrib/lua: update to 5.4.2 2021-01-13 23:56:18 -06:00
lutok Add liblutok a lightweight C++ API for lua. 2020-03-23 18:26:23 +00:00
mandoc flua: Add a libjail module 2020-10-24 17:08:59 +00:00
mknod
mtree fts_read: Handle error from a NULL return better. 2020-12-08 23:38:26 +00:00
ncurses Update to 6.2-20200215 2020-02-19 17:09:08 +00:00
netbsd-tests grep: fix -A handling in conjunction with -m match limitation 2021-02-08 12:41:22 -06:00
netcat Adjust .Dd, missed in r363084. 2020-07-10 19:58:07 +00:00
ngatm
ntp MFV r362565: 2020-06-24 01:51:05 +00:00
nvi Fix buildworld on Linux/macOS after nvi update 2020-10-12 10:42:24 +00:00
ofed infiniband-diags: Fix memory leak in dump_multicast_tables 2020-08-31 16:18:48 +00:00
one-true-awk Fix another UBSan error in awk 2020-09-21 19:03:12 +00:00
openbsm Fixup some incorrect information and some comments. These changes 2020-07-28 20:06:16 +00:00
opencsd/decoder Update opencsd to 0.14.2 2020-06-17 10:42:20 +00:00
openpam Merge upstream r948: fix race condition in openpam_ttyconv(3). 2020-11-19 05:46:59 +00:00
openresolv MFV 354917, 354918, 354919 2019-11-20 23:56:20 +00:00
opie
pam_modules/pam_passwdqc
pf
pjdfstest
pnglite pnglite: should use ntohl 2021-01-12 00:56:35 +02:00
pnpinfo
processor-trace Update Intel Processor Trace decoder library. 2019-10-10 12:46:34 +00:00
sendmail Key decleration of union semun on src version 2020-10-26 17:52:28 +00:00
serf serf: Fix the default return value of the BIO control method. 2021-02-03 14:59:32 -08:00
smbfs mount_smbfs: Issue a warning when .nsmbrc section name contains lowercase characters. 2020-01-03 12:54:14 +00:00
sqlite3 Import sqlite 3.34.1 (3340100). 2021-01-25 20:24:44 -08:00
subversion Update Subversion to 1.14.0 LTS. See contrib/subversion/CHANGES for a 2020-06-01 10:27:05 +00:00
tcp_wrappers
tcpdump Revert r362466 2020-06-22 07:46:24 +00:00
tcsh MFV r359393: tcsh: import 6974bc35a5cd 2020-03-28 15:00:55 +00:00
telnet Set stdout & stderr unbuffered, so that the "telnet>" prompt 2020-12-29 21:05:48 +00:00
terminus contrib: setup terminus 2021-01-02 21:03:28 +02:00
tnftp Fix poor performance of ftp(1) due to small SO_SNDBUF and SO_RCVBUF. 2020-02-27 19:49:59 +00:00
traceroute ping: fix some man pages and tests after r368045 2020-11-26 04:55:02 +00:00
tzcode ctime(3): Bump .Dd after r362165 2020-06-17 11:57:48 +00:00
tzdata contrib/tzdata: import tzdata 2021a 2021-01-25 08:18:14 +08:00
unbound MFV r368746: 2020-12-18 04:23:20 +00:00
unvis
vis
wpa Fix build following bfc99943b0. 2021-01-25 14:46:45 -08:00
xz liblzma: Make liblzma use libmd implementation of SHA256. 2020-06-20 21:32:07 +00:00