components_bt/bluedroid: Fix Memory&String Copy Build Err

1. When setting compilier into -O2 optimization, build for classic bt demo will get wrong
   2. Fix a memcpy bug that maybe get memory truncated

Closes https://github.com/espressif/esp-idf/issues/9398
This commit is contained in:
weitianhua
2022-07-22 13:16:44 +08:00
parent e7e350d439
commit e51df179ad
11 changed files with 84 additions and 101 deletions
@@ -174,8 +174,8 @@ void BTA_DmSetDeviceName(const char *p_name)
if ((p_msg = (tBTA_DM_API_SET_NAME *) osi_malloc(sizeof(tBTA_DM_API_SET_NAME))) != NULL) {
p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
/* truncate the name if needed */
BCM_STRNCPY_S((char *)p_msg->name, p_name, BD_NAME_LEN - 1);
p_msg->name[BD_NAME_LEN - 1] = 0;
BCM_STRNCPY_S((char *)p_msg->name, p_name, BD_NAME_LEN);
p_msg->name[BD_NAME_LEN] = '\0';
bta_sys_sendmsg(p_msg);
}