[PATCH] ifconfig: Avoid superfluous write to const string

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


Sorry, this patch is wrong. The *p = '\0' assignment is necessary so 
that later calls to inet_aton(), gethostbyname() and getnetbyname() work.

On 13/05/2019 08:39, Sebastian Huber wrote:
> ---
>   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;

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the freebsd-hackers mailing list