svn commit: r279951 - head/sbin/ifconfig
John Baldwin
jhb at FreeBSD.org
Fri Mar 13 09:45:07 UTC 2015
Author: jhb
Date: Fri Mar 13 09:45:06 2015
New Revision: 279951
URL: https://svnweb.freebsd.org/changeset/base/279951
Log:
Simplify string mangling in ifmaybeload().
- Use strlcpy() instead of strcpy().
- Use strlcat() instead of a strlcpy() with a magic number subtracted
from the length.
- Replace strncmp(..., strlen(foo) + 1) with strcmp(...).
Differential Revision: https://reviews.freebsd.org/D1814
Reviewed by: rpaulo
MFC after: 2 weeks
Modified:
head/sbin/ifconfig/ifconfig.c
Modified: head/sbin/ifconfig/ifconfig.c
==============================================================================
--- head/sbin/ifconfig/ifconfig.c Fri Mar 13 09:41:27 2015 (r279950)
+++ head/sbin/ifconfig/ifconfig.c Fri Mar 13 09:45:06 2015 (r279951)
@@ -1280,9 +1280,8 @@ ifmaybeload(const char *name)
}
/* turn interface and unit into module name */
- strcpy(ifkind, "if_");
- strlcpy(ifkind + MOD_PREFIX_LEN, ifname,
- sizeof(ifkind) - MOD_PREFIX_LEN);
+ strlcpy(ifkind, "if_", sizeof(ifkind));
+ strlcat(ifkind, ifname, sizeof(ifkind));
/* scan files in kernel */
mstat.version = sizeof(struct module_stat);
@@ -1299,8 +1298,8 @@ ifmaybeload(const char *name)
cp = mstat.name;
}
/* already loaded? */
- if (strncmp(ifname, cp, strlen(ifname) + 1) == 0 ||
- strncmp(ifkind, cp, strlen(ifkind) + 1) == 0)
+ if (strcmp(ifname, cp) == 0 ||
+ strcmp(ifkind, cp) == 0)
return;
}
}
More information about the svn-src-all
mailing list