Fixed Coverity issue : 1013549, 1013553, 1013556, 1013557, 1013560, 79/186179/1 accepted/tizen/unified/20180808.063426 submit/tizen/20180808.034959
authorsaerome.kim <saerome.kim@samsung.com>
Wed, 8 Aug 2018 02:51:35 +0000 (11:51 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Wed, 8 Aug 2018 02:51:35 +0000 (11:51 +0900)
101356210135631013566

Change-Id: Ib351e1fa147236c83d83a1bda484d6b072bf8d02
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
common/zb-utils.c
src/zbl-zcl.c

index 6a8ac076bce856c5e51af253dd22d64f37c8db61..980d95ca10a493e3f0b2627ed765be0996107504 100644 (file)
@@ -339,7 +339,7 @@ int zb_zcl_get_data_size(zb_zcl_data_type_e type)
                if (attribute_sizes[i].type == type)
                        return attribute_sizes[i].size;
        }
-       return -1;
+       return 0;
 }
 
 const char* zb_zcl_get_data_type_str(zb_zcl_data_type_e type)
index 3c0f845c2a2fcfd300a68fe8d76883b4990bd690..5dc51cd987b59b4ac72666bc489891660651c926 100644 (file)
@@ -55,6 +55,9 @@ API int zb_read_attr_status_record_clone(zb_zcl_read_attr_status_record_h src,
        RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER);
 
+       len = zb_zcl_get_data_size(srcs->type);
+       RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA);
+
        desc = calloc(1, sizeof(struct read_attribute_status_record_s));
        RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
 
@@ -67,8 +70,6 @@ API int zb_read_attr_status_record_clone(zb_zcl_read_attr_status_record_h src,
                return ZIGBEE_ERROR_OUT_OF_MEMORY;
        }
 
-       len = zb_zcl_get_data_size(srcs->type);
-       RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA);
        memcpy(desc->value, srcs->value, len);
        *dst = desc;
 
@@ -379,12 +380,15 @@ API int zb_write_attr_record_clone(zb_zcl_write_attr_record_h src,
        RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER);
 
+       len = zb_zcl_get_data_size(srcs->type);
+       RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA);
+
        desc = calloc(1, sizeof(struct write_attribute_record_s));
        RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
 
        memcpy(desc, src, sizeof(struct write_attribute_record_s));
 
-       desc->value = calloc(1, zb_zcl_get_data_size(srcs->type));
+       desc->value = calloc(1, len);
        if (NULL == desc->value) {
                free(desc);
                desc = NULL;
@@ -393,9 +397,6 @@ API int zb_write_attr_record_clone(zb_zcl_write_attr_record_h src,
                return ZIGBEE_ERROR_OUT_OF_MEMORY;
        }
 
-       len = zb_zcl_get_data_size(srcs->type);
-       RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA);
-
        memcpy(desc->value, srcs->value, len);
        *dst = desc;
 
@@ -612,12 +613,15 @@ API int zb_report_config_record_clone(zb_zcl_reporting_config_record_h src,
        RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER);
 
+       len = zb_zcl_get_data_size(srcs->type);
+       RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA);
+
        desc = calloc(1, sizeof(struct reporting_configuration_record_s));
        RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
 
        memcpy(desc, src, sizeof(struct reporting_configuration_record_s));
 
-       desc->change = calloc(1, zb_zcl_get_data_size(srcs->type));
+       desc->change = calloc(1, len);
        if (NULL == desc->change) {
                free(desc);
                desc = NULL;
@@ -625,9 +629,6 @@ API int zb_report_config_record_clone(zb_zcl_reporting_config_record_h src,
                return ZIGBEE_ERROR_OUT_OF_MEMORY;
        }
 
-       len = zb_zcl_get_data_size(srcs->type);
-       RETV_IF(0 >= len, ZIGBEE_ERROR_NO_DATA);
-
        memcpy(desc->change, srcs->change, len);
        *dst = desc;