API int zb_read_attr_status_record_clone(zb_zcl_read_attr_status_record_h src,
zb_zcl_read_attr_status_record_h *dst)
{
+ int len = -1;
struct read_attribute_status_record_s *srcs = src;
struct read_attribute_status_record_s *desc = NULL;
memcpy(desc, src, sizeof(struct read_attribute_status_record_s));
desc->value = calloc(1, zb_zcl_get_data_size(srcs->type));
- RETVM_IF(NULL == desc->value, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
- memcpy(desc->value, srcs->value, zb_zcl_get_data_size(srcs->type));
+ if (NULL == desc->value) {
+ free(desc);
+ desc = NULL;
+ ERR("calloc() Fail(%d)", errno);
+ 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;
return ZIGBEE_ERROR_NONE;
h->value = calloc(count + ZB_ZCL_OCTET_SIZE + ZB_GUARD_CHAR, sizeof(char));
RETV_IF(NULL == h->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
- h->value[0] = count;
+ h->value[0] = (unsigned char)count;
memcpy(h->value + ZB_ZCL_OCTET_SIZE, value + ZB_ZCL_OCTET_SIZE, count);
} else if (ZB_ZCL_LONG_OCTET_STRING == type || ZB_ZCL_LONG_CHARACTER_STRING == type) {
h->value = calloc(count + ZB_ZCL_LONG_OCTET_SIZE + ZB_GUARD_CHAR, sizeof(char));
RETV_IF(NULL == h->value, ZIGBEE_ERROR_OUT_OF_MEMORY);
- h->value[0] = count & 0xff;
- h->value[1] = (count >> 8) & 0xff ;
+ h->value[0] = (unsigned char)count & 0xff;
+ h->value[1] = (unsigned char)(count >> 8) & 0xff ;
memcpy(h->value + ZB_ZCL_LONG_OCTET_SIZE, value, len);
} else {
API int zb_write_attr_record_clone(zb_zcl_write_attr_record_h src,
zb_zcl_write_attr_record_h *dst)
{
+ int len = -1;
struct write_attribute_record_s *srcs = src;
struct write_attribute_record_s *desc = NULL;
memcpy(desc, src, sizeof(struct write_attribute_record_s));
desc->value = calloc(1, zb_zcl_get_data_size(srcs->type));
- RETVM_IF(NULL == desc->value, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
+ if (NULL == desc->value) {
+ free(desc);
+ desc = NULL;
- memcpy(desc->value, srcs->value, zb_zcl_get_data_size(srcs->type));
+ ERR("calloc() Fail(%d)", errno);
+ 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;
return ZIGBEE_ERROR_NONE;
API int zb_report_config_record_clone(zb_zcl_reporting_config_record_h src,
zb_zcl_reporting_config_record_h *dst)
{
+ int len = -1;
struct reporting_configuration_record_s *srcs = src;
struct reporting_configuration_record_s *desc = NULL;
memcpy(desc, src, sizeof(struct reporting_configuration_record_s));
desc->change = calloc(1, zb_zcl_get_data_size(srcs->type));
- RETVM_IF(NULL == desc->change, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
+ if (NULL == desc->change) {
+ free(desc);
+ desc = NULL;
+ ERR("calloc() Fail(%d)", errno);
+ 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, zb_zcl_get_data_size(srcs->type));
+ memcpy(desc->change, srcs->change, len);
*dst = desc;
return ZIGBEE_ERROR_NONE;
memcpy(desc, srcs, sizeof(struct attribute_report_s));
desc->value = calloc(1, zb_zcl_get_data_size(srcs->type));
- RETVM_IF(NULL == desc->value, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
+ if (NULL == desc->value) {
+ free(desc);
+ desc = NULL;
+ ERR("calloc() Fail(%d)", errno);
+ return ZIGBEE_ERROR_OUT_OF_MEMORY;
+ }
memcpy(desc->value, srcs->value, zb_zcl_get_data_size(srcs->type));
*dst = desc;