ucs_binding.c: Fix compiler warnings 43/12843/1
authorTobias Jahnke <tobias.jahnke@microchip.com>
Thu, 14 Dec 2017 08:03:20 +0000 (09:03 +0100)
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>
Wed, 20 Dec 2017 17:12:02 +0000 (17:12 +0000)
Bug-AGL: SPEC-1177

Fix compiler warnings due to the use of deprecated json-c functions.

Change-Id: I8fc783af7f1cbf436d9a979395b6f6cf3c5d511d
Signed-off-by: Tobias Jahnke <tobias.jahnke@microchip.com>
ucs2-afb/ucs_binding.c

index ca1f756..b72aca9 100644 (file)
@@ -584,28 +584,34 @@ STATIC void ucs2_writei2c_cmd(struct afb_req request, json_object *j_obj) {
     uint8_t i2c_data_sz = 0;
     uint16_t node_addr = 0;
     struct afb_req *async_req_ptr = NULL;
+    json_object *j_tmp;
+    json_bool key_found;
 
-    node_addr = (uint16_t)json_object_get_int(json_object_object_get(j_obj, "node"));
-    AFB_NOTICE("node_address: 0x%02X", node_addr);
-
-    if (node_addr == 0) {
-        afb_req_fail_f(request, "query-params","params wrong or missing");
+    if (json_object_object_get_ex(j_obj, "node", &j_tmp)) {
+        node_addr = (uint16_t)json_object_get_int(j_tmp);
+        AFB_NOTICE("node_address: 0x%02X", node_addr);
+        if (node_addr == 0) {
+            afb_req_fail_f(request, "query-params","param node invalid type");
+            goto OnErrorExit;
+        }
+    }
+    else {
+        afb_req_fail_f(request, "query-params","param node missing");
         goto OnErrorExit;
     }
 
-    if (json_object_get_type(json_object_object_get(j_obj, "data"))==json_type_array) {
-        int size = json_object_array_length(json_object_object_get(j_obj, "data"));
+    key_found = json_object_object_get_ex(j_obj, "data", &j_tmp);
+    if (key_found && (json_object_get_type(j_tmp)==json_type_array)) {
+        int size = json_object_array_length(j_tmp);
         if ((size > 0) && (size <= I2C_MAX_DATA_SZ)) {
 
             int32_t i;
             int32_t val;
             struct json_object *j_elem;
-            struct json_object *j_arr = json_object_object_get(j_obj, "data");
 
             for (i = 0; i < size; i++) {
 
-
-                j_elem = json_object_array_get_idx(j_arr, i);
+                j_elem = json_object_array_get_idx(j_tmp, i);
                 val = json_object_get_int(j_elem);
                 if ((val < 0) && (val > 0xFF)){
                     i = 0;
@@ -677,6 +683,10 @@ STATIC void ucs2_sendmessage_cmd(struct afb_req request, json_object *j_obj) {
     if (json_object_object_get_ex(j_obj, "node", &j_tmp)) {
         node_addr = (uint16_t)json_object_get_int(j_tmp);
         AFB_NOTICE("node_address: 0x%02X", node_addr);
+        if (node_addr == 0) {
+            afb_req_fail_f(request, "query-params","param node invalid type");
+            goto OnErrorExit;
+        }
     }
     else {
         afb_req_fail_f(request, "query-params","param node missing");
@@ -684,8 +694,14 @@ STATIC void ucs2_sendmessage_cmd(struct afb_req request, json_object *j_obj) {
     }
 
     if (json_object_object_get_ex(j_obj, "msgid", &j_tmp)) {
-        msg_id = (uint16_t)json_object_get_int(j_tmp);
-        AFB_NOTICE("msgid: 0x%02X", msg_id);
+        if (json_object_get_type(j_tmp) == json_type_int) {
+            msg_id = (uint16_t)json_object_get_int(j_tmp);
+            AFB_NOTICE("msgid: 0x%02X", msg_id);
+        }
+        else {
+            afb_req_fail_f(request, "query-params","param msgid invalid type");
+            goto OnErrorExit;
+        }
     }
     else {
         afb_req_fail_f(request, "query-params","param msgid missing");