Skip to contentSkip to conversation

ethtool: fix long statistics name

PATCH Applied Stephen Hemminger 2 participants 2 messages Jan 11, 2007 – Feb 9, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ethtool: fix long statistics name

Fix handling of statistics where the label is exactly 32 (ETH_GSTRING_LEN) characters long (observed with chelsio 10G driver).
Before it would print garbage because of going by end
of string. Don't need to copy string, just use formats properly.

---
 ethtool.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
ethtool.c +4 -6
index 6e68009..0a50144 100644
@@ -1989,12 +1989,10 @@ static int do_gstats(int fd, struct ifre
 	/* todo - pretty-print the strings per-driver */
 	fprintf(stdout, "NIC statistics:\n");
 	for (i = 0; i < n_stats; i++) {
-		char s[ETH_GSTRING_LEN];
-
-		strncpy(s, (const char *) &strings->data[i * ETH_GSTRING_LEN],
-			ETH_GSTRING_LEN);
-		fprintf(stdout, "     %s: %llu\n",
-			s, stats->data[i]);
+		fprintf(stdout, "     %.*s: %llu\n",
+			ETH_GSTRING_LEN, 
+			&strings->data[i * ETH_GSTRING_LEN],
+			stats->data[i]);
 	}
 	free(strings);
 	free(stats);
Signature · 1 line
1.4.1
Applied
#1 lore raw
Quoted 8 lines · Stephen Hemminger

Fix handling of statistics where the label is exactly 32 (ETH_GSTRING_LEN)
characters long (observed with chelsio 10G driver). Before it would print garbage because of going by end of string. Don't need to copy string, just use formats properly.

---
 ethtool.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

applied