Switch from memmove() to memcpy() where appropriate; simplify address
authorguenther <guenther@openbsd.org>
Sun, 20 Jul 2014 09:59:42 +0000 (09:59 +0000)
committerguenther <guenther@openbsd.org>
Sun, 20 Jul 2014 09:59:42 +0000 (09:59 +0000)
parsing logic; eliminate an inefficient use of MIN() macro

usr.bin/telnet/commands.c
usr.bin/telnet/ring.c
usr.bin/telnet/sys_bsd.c

index bc9bbfb..8b59a92 100644 (file)
@@ -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);
 }
index d6833e8..6c3d559 100644 (file)
@@ -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 $ */
 
 /*
  */
 
 /* 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;
index 2679ff0..658fd8a 100644 (file)
@@ -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