Module Name:    src
Committed By:   christos
Date:           Fri Aug  5 07:22:17 UTC 2016

Modified Files:
        src/usr.bin/systat: ifstat.c

Log Message:
Avoid string gymnastics in an olympic year.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/systat/ifstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/ifstat.c
diff -u src/usr.bin/systat/ifstat.c:1.3 src/usr.bin/systat/ifstat.c:1.4
--- src/usr.bin/systat/ifstat.c:1.3	Thu Aug  4 08:56:31 2016
+++ src/usr.bin/systat/ifstat.c	Fri Aug  5 03:22:17 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ifstat.c,v 1.3 2016/08/04 12:56:31 jakllsch Exp $	*/
+/*	$NetBSD: ifstat.c,v 1.4 2016/08/05 07:22:17 christos Exp $	*/
 
 /*
  * Copyright (c) 2003, Trent Nelson, <tr...@arpa.com>.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ifstat.c,v 1.3 2016/08/04 12:56:31 jakllsch Exp $");
+__RCSID("$NetBSD: ifstat.c,v 1.4 2016/08/05 07:22:17 christos Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -350,24 +350,11 @@ fetchifstat(void)
 static void
 right_align_string(struct if_stat *ifp)
 {
-	int	 str_len = 0, pad_len = 0;
-	char	*newstr = NULL, *ptr = NULL;
-
 	if (ifp == NULL || ifp->if_mib.ifdr_name[0] == '\0')
 		return;
-	else {
-		/* string length + '\0' */
-		str_len = strlen(ifp->if_mib.ifdr_name)+1;
-		pad_len = IF_NAMESIZE-(str_len);
-
-		newstr = ifp->if_name;
-		ptr = newstr + pad_len;
-		(void)memset((void *)newstr, (int)' ', IF_NAMESIZE);
-		(void)strncpy(ptr, (const char *)&ifp->if_mib.ifdr_name,
-			      str_len);
-	}
 
-	return;
+	snprintf(ifp->if_name, IF_NAMESIZE, "%*s", IF_NAMESIZE - 1,
+	    ifp->if_mib.ifdr_name);
 }
 
 static int

Reply via email to