Fix coverity issues 03/153003/1 accepted/tizen/unified/20170929.082116 submit/tizen/20170927.234521 submit/tizen/20170927.235008 submit/tizen/20170929.023158
authorsaerome kim <saerome.kim@samsung.com>
Wed, 27 Sep 2017 12:59:24 +0000 (21:59 +0900)
committersaerome kim <saerome.kim@samsung.com>
Wed, 27 Sep 2017 12:59:24 +0000 (21:59 +0900)
- Fix incorrect expression issues
- Fix integer handling issues

Change-Id: I58a5d186b683c6ad45133a251f00591c872cd20e
Signed-off-by: saerome kim <saerome.kim@samsung.com>
include/zb_zcl.h
lib/zbl_zcl.c

index a26de6ff7163c42c9a16d6979a3f655c95b906ca..f2c6f23246de31b0d6fc6852bd9a2e7f477d3b45 100644 (file)
@@ -154,7 +154,7 @@ int zb_get_analog_or_discret(unsigned char type);
  * @return size of attribute data type
  *
  */
-int zb_get_data_size(unsigned char type);
+int zb_get_data_size(zb_zcl_data_type_e type);
 
 /**
  * @brief Creates simple value data
index 44bdb444f8cfd050e68a3ca1fc3b9d997b36f88c..f5c99f7b44fd0261645a6045c02c7a5f51c075c9 100644 (file)
@@ -420,7 +420,7 @@ API int zb_get_analog_or_discret(unsigned char type)
        return analog_discrete_thresholds[index+1];
 }
 
-API int zb_get_data_size(unsigned char type)
+API int zb_get_data_size(zb_zcl_data_type_e type)
 {
        int i;
        int count;
@@ -623,19 +623,17 @@ API int zb_set_value_to_read_attr_status_record(read_attr_status_record_h handle
                memcpy(h->value, v->val, len);
        } else if (ZB_ZCL_OCTAT_STRING == type || ZB_ZCL_CHRACTER_STRING == type) {
                RETV_IF(NULL == v->str, ZIGBEE_ERROR_NO_DATA);
-               h->value = calloc(v->str->n + sizeof(v->str->n), sizeof(char));
+               h->value = calloc(v->str->n + sizeof(char), sizeof(char));
                RETV_IF(NULL == h->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
                h->value[0] = v->str->n;
-               memcpy(h->value + sizeof(v->str->n),
-                       v->str->v+sizeof(v->str->n), v->str->n);
+               memcpy(h->value + sizeof(char), v->str->v + sizeof(char), v->str->n);
        } else if (ZB_ZCL_LONG_OCTAT_STRING == type || ZB_ZCL_LONG_CHRACTER_STRING == type) {
                RETV_IF(NULL == v->wstr, ZIGBEE_ERROR_NO_DATA);
-               h->value = calloc(v->wstr->n + sizeof(v->wstr->n), sizeof(char));
+               h->value = calloc(v->wstr->n + sizeof(short), sizeof(char));
                RETV_IF(NULL == h->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
                h->value[0] = v->wstr->n & 0xff;
                h->value[1] = (v->wstr->n >> 8) & 0xff ;
-               memcpy(h->value + sizeof(v->wstr->n),
-                       v->wstr->v+sizeof(v->wstr->n), v->wstr->n);
+               memcpy(h->value + sizeof(short), v->wstr->v + sizeof(short), v->wstr->n);
        } else
                return ZIGBEE_ERROR_NOT_SUPPORTED;
 
@@ -753,15 +751,15 @@ API int zb_get_value(zb_value_h handle, unsigned char *type, unsigned char **val
                *count = len;
        } else if (ZB_ZCL_OCTAT_STRING == h->type || ZB_ZCL_CHRACTER_STRING == h->type) {
                RETV_IF(NULL == h->str, ZIGBEE_ERROR_NO_DATA);
-               s = calloc(sizeof(unsigned char), h->str->n);
+               s = calloc(sizeof(char), h->str->n);
                RETV_IF(NULL == s, ZIGBEE_ERROR_OUT_OF_MEMORY);
-               memcpy(s, h->str->v+sizeof(h->str->n), h->str->n);
+               memcpy(s, h->str->v + sizeof(char), h->str->n);
                *count = h->str->n;
        } else if (ZB_ZCL_LONG_OCTAT_STRING == h->type || ZB_ZCL_LONG_CHRACTER_STRING == h->type) {
                RETV_IF(NULL == h->wstr, ZIGBEE_ERROR_NO_DATA);
-               s = calloc(sizeof(unsigned char), h->wstr->n);
+               s = calloc(sizeof(char), h->wstr->n);
                RETV_IF(NULL == s, ZIGBEE_ERROR_OUT_OF_MEMORY);
-               memcpy(s, h->wstr->v+sizeof(h->wstr->n), h->wstr->n);
+               memcpy(s, h->wstr->v + sizeof(short), h->wstr->n);
                *count = h->wstr->n;
        } else
                return ZIGBEE_ERROR_NOT_SUPPORTED;
@@ -961,23 +959,21 @@ API int zb_set_value_to_write_attr_record(write_attr_record_h handle, zb_value_h
                RETV_IF(NULL == v->str, ZIGBEE_ERROR_NO_DATA);
                /* 1 byte string size exception case */
                RETV_IF(0xff - 1 < v->str->n, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
-               h->value = calloc(v->str->n + sizeof(v->str->n), sizeof(char));
+               h->value = calloc(v->str->n + sizeof(char), sizeof(char));
                RETV_IF(NULL == h->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
                /* The first 1 byte indicate invalid or length of string */
                h->value[0] = v->str->n & 0xff;
-               memcpy(h->value + sizeof(v->str->n),
-                       v->str->v + sizeof(v->str->n), v->str->n);
+               memcpy(h->value + sizeof(char), v->str->v + sizeof(char), v->str->n);
        } else if (ZB_ZCL_LONG_OCTAT_STRING == h->type || ZB_ZCL_LONG_CHRACTER_STRING == h->type) {
                RETV_IF(NULL == v->wstr, ZIGBEE_ERROR_NO_DATA);
                /* 2 byte string size exception case */
                RETV_IF(0xffff - 1 < v->wstr->n, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
-               h->value = calloc(v->wstr->n + sizeof(v->wstr->n), sizeof(char));
+               h->value = calloc(v->wstr->n + sizeof(short), sizeof(char));
                RETV_IF(NULL == h->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
                /* The first 2 byte indicate invalid or length of string */
                h->value[0] = v->wstr->n & 0xff;
                h->value[1] = (v->wstr->n >> 8) & 0xff ;
-               memcpy(h->value + sizeof(v->wstr->n),
-                       v->wstr->v + sizeof(v->wstr->n), v->wstr->n);
+               memcpy(h->value + sizeof(short), v->wstr->v + sizeof(short), v->wstr->n);
        } else
                return ZIGBEE_ERROR_NOT_SUPPORTED;
 
@@ -1725,21 +1721,19 @@ API int zb_set_value_to_attr_report(attr_report_h handle, zb_value_h value)
                h->type = v->type;
        } else if (ZB_ZCL_OCTAT_STRING == h->type || ZB_ZCL_CHRACTER_STRING == h->type) {
                RETV_IF(NULL == v->str, ZIGBEE_ERROR_NO_DATA);
-               h->value = calloc(v->str->n + sizeof(v->str->n), sizeof(char));
+               h->value = calloc(v->str->n + sizeof(char), sizeof(char));
                RETV_IF(NULL == h->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
                /* The first 1 byte indicate invalid or length of string */
                h->value[0] = v->str->n & 0xff;
-               memcpy(h->value + sizeof(v->str->n),
-                       v->str->v + sizeof(v->str->n), v->str->n);
+               memcpy(h->value + sizeof(char), v->str->v + sizeof(char), v->str->n);
        } else if (ZB_ZCL_LONG_OCTAT_STRING == h->type || ZB_ZCL_LONG_CHRACTER_STRING == h->type) {
                RETV_IF(NULL == v->wstr, ZIGBEE_ERROR_NO_DATA);
-               h->value = calloc(v->wstr->n + sizeof(v->wstr->n), sizeof(char));
+               h->value = calloc(v->wstr->n + sizeof(short), sizeof(char));
                RETV_IF(NULL == h->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
                /* The first 2 byte indicate invalid or length of string */
                h->value[0] = v->wstr->n & 0xff;
                h->value[1] = (v->wstr->n >> 8) & 0xff ;
-               memcpy(h->value + sizeof(v->wstr->n),
-                       v->wstr->v + sizeof(v->wstr->n), v->wstr->n);
+               memcpy(h->value + sizeof(short), v->wstr->v + sizeof(short), v->wstr->n);
        } else
                return ZIGBEE_ERROR_NOT_SUPPORTED;