aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Jahnke <tobias.jahnke@microchip.com>2017-12-14 09:03:20 +0100
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2017-12-20 17:12:02 +0000
commited3e37c3d413123a8026b40a30ef93b9c2db33d8 (patch)
tree8a001e15e1b26ef340808aa22c5878f1c1467218
parent8f7ee162b0d6412a90251aa21ee5386945546783 (diff)
ucs_binding.c: Fix compiler warnings
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>
-rw-r--r--ucs2-afb/ucs_binding.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/ucs2-afb/ucs_binding.c b/ucs2-afb/ucs_binding.c
index ca1f756..b72aca9 100644
--- a/ucs2-afb/ucs_binding.c
+++ b/ucs2-afb/ucs_binding.c
@@ -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");