git: 21c32cebf81a - main - ifconfig: skip calling fnmatch once the result no longer matters
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 27 Jun 2023 22:29:34 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=21c32cebf81aa763771607ba3d7cc71b9eaa3fa1 commit 21c32cebf81aa763771607ba3d7cc71b9eaa3fa1 Author: Alfonso Gregory <gfunni234@gmail.com> AuthorDate: 2023-06-27 22:18:55 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2023-06-27 22:28:44 +0000 ifconfig: skip calling fnmatch once the result no longer matters Because fnmatch has no side effects, we can safely avoid calling fnmatch if the end result does not matter anyway (the compiler cannot see this, so it calls fnmatch in the event it has side-effects). Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/747 --- sbin/ifconfig/ifconfig.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 5d789795e636..b26fbaf82776 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -910,11 +910,11 @@ group_member(const char *ifname, const char *match, const char *nomatch) matched = false; nomatched = true; for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(*ifg); ifg++) { - len -= sizeof(struct ifg_req); - if (match) - matched |= !fnmatch(match, ifg->ifgrq_group, 0); - if (nomatch) - nomatched &= fnmatch(nomatch, ifg->ifgrq_group, 0); + len -= sizeof(*ifg); + if (match && !matched) + matched = !fnmatch(match, ifg->ifgrq_group, 0); + if (nomatch && nomatched) + nomatched = fnmatch(nomatch, ifg->ifgrq_group, 0); } free(ifgr.ifgr_groups);