From ff39402c53c964a5dfb3eecd86191bdebdb6623e Mon Sep 17 00:00:00 2001 From: guenther Date: Sun, 20 Jul 2014 09:59:42 +0000 Subject: [PATCH] Switch from memmove() to memcpy() where appropriate; simplify address parsing logic; eliminate an inefficient use of MIN() macro --- usr.bin/telnet/commands.c | 24 +++++++++++------------- usr.bin/telnet/ring.c | 13 +++++-------- usr.bin/telnet/sys_bsd.c | 4 ++-- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index bc9bbfbd78b..8b59a9299e1 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commands.c,v 1.64 2014/07/20 09:31:25 guenther Exp $ */ +/* $OpenBSD: commands.c,v 1.65 2014/07/20 09:59:42 guenther Exp $ */ /* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */ /* @@ -2367,7 +2367,7 @@ sourceroute(arg, cpp, lenp) { static char lsr[44]; char *cp, *cp2, *lsrp, *lsrep; - struct in_addr sin_addr; + struct in_addr addr; struct hostent *host = 0; char c; @@ -2412,7 +2412,7 @@ sourceroute(arg, cpp, lenp) cp++; - sin_addr.s_addr = 0; + addr.s_addr = 0; for (c = 0;;) { if (c == ':') @@ -2433,16 +2433,14 @@ sourceroute(arg, cpp, lenp) if (!c) cp2 = 0; - if ((sin_addr.s_addr = inet_addr(cp)) != INADDR_NONE) { - } else if ((host = gethostbyname(cp))) { - memmove((caddr_t)&sin_addr, - host->h_addr_list[0], - sizeof(sin_addr)); - } else { - *cpp = cp; - return(0); + if ((addr.s_addr = inet_addr(cp)) == INADDR_NONE) { + if ((host = gethostbyname(cp)) == NULL) { + *cpp = cp; + return(0); + } + memcpy(&addr, host->h_addr_list[0], sizeof addr); } - memmove(lsrp, (char *)&sin_addr, 4); + memcpy(lsrp, &addr, 4); lsrp += 4; if (cp2) cp = cp2; @@ -2461,5 +2459,5 @@ sourceroute(arg, cpp, lenp) } *lsrp++ = IPOPT_NOP; /* 32 bit word align it */ *lenp = lsrp - *cpp; - return(sin_addr.s_addr); + return(addr.s_addr); } diff --git a/usr.bin/telnet/ring.c b/usr.bin/telnet/ring.c index d6833e8d744..6c3d559ffd4 100644 --- a/usr.bin/telnet/ring.c +++ b/usr.bin/telnet/ring.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ring.c,v 1.8 2014/07/20 08:12:46 guenther Exp $ */ +/* $OpenBSD: ring.c,v 1.9 2014/07/20 09:59:42 guenther Exp $ */ /* $NetBSD: ring.c,v 1.7 1996/02/28 21:04:07 thorpej Exp $ */ /* @@ -45,11 +45,6 @@ */ /* Internal macros */ - -#if !defined(MIN) -#define MIN(a,b) (((a)<(b))? (a):(b)) -#endif /* !defined(MIN) */ - #define ring_subtract(d,a,b) (((a)-(b) >= 0)? \ (a)-(b): (((a)-(b))+(d)->size)) @@ -262,8 +257,10 @@ ring_supply_data(ring, buffer, count) int i; while (count) { - i = MIN(count, ring_empty_consecutive(ring)); - memmove(ring->supply, buffer, i); + i = ring_empty_consecutive(ring); + if (i > count) + i = count; + memcpy(ring->supply, buffer, i); ring_supplied(ring, i); count -= i; buffer += i; diff --git a/usr.bin/telnet/sys_bsd.c b/usr.bin/telnet/sys_bsd.c index 2679ff04299..658fd8a2592 100644 --- a/usr.bin/telnet/sys_bsd.c +++ b/usr.bin/telnet/sys_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_bsd.c,v 1.22 2014/07/20 09:31:25 guenther Exp $ */ +/* $OpenBSD: sys_bsd.c,v 1.23 2014/07/20 09:59:42 guenther Exp $ */ /* $NetBSD: sys_bsd.c,v 1.11 1996/02/28 21:04:10 thorpej Exp $ */ /* @@ -194,7 +194,7 @@ tcval(func) void TerminalDefaultChars() { - memmove(new_tc.c_cc, old_tc.c_cc, sizeof(old_tc.c_cc)); + memcpy(new_tc.c_cc, old_tc.c_cc, sizeof(old_tc.c_cc)); # ifndef VDISCARD termFlushChar = CONTROL('O'); # endif -- 2.20.1