Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 May 2019 08:39:51 +0200
From:      Sebastian Huber <sebastian.huber@embedded-brains.de>
To:        freebsd-hackers@freebsd.org
Subject:   [PATCH] ifconfig: Avoid superfluous write to const string
Message-ID:  <20190513063951.6521-1-sebastian.huber@embedded-brains.de>

next in thread | raw e-mail | index | archive | help
---
 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20190513063951.6521-1-sebastian.huber>