[Olsr-dev] [PATCH v1 111/115] jsoninfo: helpers: use sizeof() for buffers

Ferry Huberts (spam-protected)
Wed Dec 2 21:29:24 CET 2015


From: Ferry Huberts <(spam-protected)>

Plus an extra 'ensure 0 termination'

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 lib/jsoninfo/src/olsrd_jsoninfo_helpers.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c b/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
index 28ea4c8..36d8282 100644
--- a/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
+++ b/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
@@ -172,7 +172,7 @@ static int get_string_from_file(const char* filename, char* buf, int len) {
 
 static int abuf_json_sysdata(struct autobuf *abuf, const char* key, const char* syspath) {
   char buf[256];
-  int ret = get_string_from_file(syspath, buf, 256);
+  int ret = get_string_from_file(syspath, buf, sizeof(buf));
   if (*buf)
     abuf_json_string(abuf, key, buf);
   return ret;
@@ -180,7 +180,8 @@ static int abuf_json_sysdata(struct autobuf *abuf, const char* key, const char*
 
 void abuf_json_sys_class_net(struct autobuf *abuf, const char* key, const char* ifname, const char* datapoint) {
   char filename[256];
-  snprintf(filename, 255, "/sys/class/net/%s/%s", ifname, datapoint);
+  snprintf(filename, sizeof(filename) - 1, "/sys/class/net/%s/%s", ifname, datapoint);
+  filename[sizeof(filename) - 1] = '\0';
   abuf_json_sysdata(abuf, key, filename);
 }
 #endif /* __linux__ */
-- 
2.5.0




More information about the Olsr-dev mailing list