From 21c32cebf81aa763771607ba3d7cc71b9eaa3fa1 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Tue, 27 Jun 2023 16:18:55 -0600 Subject: [PATCH] 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 5d789795e63..b26fbaf8277 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);