From b31382fbd7cd8d19528694abd61e4df7cca1a633 Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 5 Aug 2016 07:22:17 +0000 Subject: [PATCH] Avoid string gymnastics in an olympic year. --- usr.bin/systat/ifstat.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/usr.bin/systat/ifstat.c b/usr.bin/systat/ifstat.c index 423125e8b339..639232f8bd71 100644 --- a/usr.bin/systat/ifstat.c +++ b/usr.bin/systat/ifstat.c @@ -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, . @@ -32,7 +32,7 @@ #include #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 @@ -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