[PATCH] ifconfig: Avoid superfluous write to const string

Sebastian Huber sebastian.huber at embedded-brains.de
Mon May 13 06:40:04 UTC 2019


---
 sbin/ifconfig/af_inet.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c
index 3d44a4c0b99..279a31773f4 100644
--- a/sbin/ifconfig/af_inet.c
+++ b/sbin/ifconfig/af_inet.c
@@ -141,20 +141,18 @@ in_getaddr(const char *s, int which)
 	sin->sin_family = AF_INET;
 
 	if (which == ADDR) {
-		char *p = NULL;
+		const char *p = strrchr(s, '/');
 
-		if((p = strrchr(s, '/')) != NULL) {
+		if (p != NULL) {
 			const char *errstr;
 			/* address is `name/masklen' */
 			int masklen;
 			struct sockaddr_in *min = sintab[MASK];
-			*p = '\0';
 			if (!isdigit(*(p + 1)))
 				errstr = "invalid";
 			else
 				masklen = (int)strtonum(p + 1, 0, 32, &errstr);
 			if (errstr != NULL) {
-				*p = '/';
 				errx(1, "%s: bad value (width %s)", s, errstr);
 			}
 			min->sin_family = AF_INET;
-- 
2.16.4



More information about the freebsd-hackers mailing list