[Olsr-dev] [PATCH v1 110/115] jsoninfo: helpers: get_string_from_file ensures '\0' in the first byte
Ferry Huberts
(spam-protected)
Wed Dec 2 21:29:23 CET 2015
From: Ferry Huberts <(spam-protected)>
Signed-off-by: Ferry Huberts <(spam-protected)>
---
lib/jsoninfo/src/olsrd_jsoninfo_helpers.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c b/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
index 6f3f42a..28ea4c8 100644
--- a/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
+++ b/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
@@ -158,6 +158,7 @@ void abuf_json_float(struct autobuf *abuf, const char* key, float value) {
static int get_string_from_file(const char* filename, char* buf, int len) {
int bytes = -1;
int fd = open(filename, O_RDONLY);
+ buf[0] = '\0';
if (fd > -1) {
bytes = read(fd, buf, len);
if (bytes < len)
@@ -170,10 +171,8 @@ 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) {
- int ret = -1;
char buf[256];
- *buf = 0;
- ret = get_string_from_file(syspath, buf, 256);
+ int ret = get_string_from_file(syspath, buf, 256);
if (*buf)
abuf_json_string(abuf, key, buf);
return ret;
--
2.5.0
More information about the Olsr-dev
mailing list