From: saerome kim Date: Wed, 27 Sep 2017 12:59:24 +0000 (+0900) Subject: Fix coverity issues X-Git-Tag: submit/tizen/20170927.234521^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e1f0361176d460dd1b7aa0e3d4e8f1720e3f466;p=platform%2Fcore%2Fapi%2Fzigbee.git Fix coverity issues - Fix incorrect expression issues - Fix integer handling issues Change-Id: I58a5d186b683c6ad45133a251f00591c872cd20e Signed-off-by: saerome kim --- diff --git a/include/zb_zcl.h b/include/zb_zcl.h index a26de6f..f2c6f23 100644 --- a/include/zb_zcl.h +++ b/include/zb_zcl.h @@ -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 diff --git a/lib/zbl_zcl.c b/lib/zbl_zcl.c index 44bdb44..f5c99f7 100644 --- a/lib/zbl_zcl.c +++ b/lib/zbl_zcl.c @@ -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;