From 422cadfd5ffd78ae1b8fdf15734e03bd0333b26e Mon Sep 17 00:00:00 2001 From: Laslo Hunhold Date: Sat, 19 May 2018 19:33:04 +0200 Subject: Implement esnprintf() and make formatted calls more efficient Within the components, snprintf() was unchecked and had inefficient calls in some places. We implement esnprintf() that does all the dirty laundry for us and use it exclusively now. --- components/netspeeds.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'components/netspeeds.c') diff --git a/components/netspeeds.c b/components/netspeeds.c index b4e6972..6adc3ea 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -17,8 +17,11 @@ oldrxbytes = rxbytes; - snprintf(path, sizeof(path), - "/sys/class/net/%s/statistics/rx_bytes", interface); + if (esnprintf(path, sizeof(path), + "/sys/class/net/%s/statistics/rx_bytes", + interface) < 0) { + return NULL; + } if (pscanf(path, "%llu", &rxbytes) != 1) { return NULL; } @@ -37,8 +40,11 @@ oldtxbytes = txbytes; - snprintf(path, sizeof(path), - "/sys/class/net/%s/statistics/tx_bytes", interface); + if (esnprintf(path, sizeof(path), + "/sys/class/net/%s/statistics/tx_bytes", + interface) < 0) { + return NULL; + } if (pscanf(path, "%llu", &txbytes) != 1) { return NULL; } -- cgit v1.2.3