[OpenWrt-Devel] [PATCH 4/4] blobmsg_add_json_from_file(): fixed const-correctness with libjson

Bachtin, Dmitri dbachtin at init-ka.de
Wed Sep 9 03:23:59 EDT 2015


libjson's json_object_from_file takes a non-const char buffer as
its second parameter while libjson-c takes a const one. Use
strdup() to avoid using const data as non-const.

Signed-off-by: Dmitri Bachtin <dbachtin at init-ka.de>
---
 blobmsg_json.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/blobmsg_json.c b/blobmsg_json.c
index ffde23d..de876cf 100644
--- a/blobmsg_json.c
+++ b/blobmsg_json.c
@@ -97,7 +97,10 @@ out:
 
 bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file)
 {
-	return __blobmsg_add_json(b, json_object_from_file(file));
+	char* __file = strdup(file);
+	bool result = __blobmsg_add_json(b, json_object_from_file(__file));
+	free(__file);
+	return result;
 }
 
 bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str)
-- 
1.7.2.5
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list