target/xtensa: fix clang analyzer warnings and gcc12 build errors

Fix Unused code	Dead assignment at line 657
Fix Memory error Double free at line 2851
Fix Memory error Memory leak at line 2530
Fix error: 'a3' may be used uninitialized at line 758
Fix error: '%04x' directive writing between 4 and 8 bytes
into a region of size 5 at line 2471

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: I0382a622bc7c4108a335fd741816577e79240397
Reviewed-on: https://review.openocd.org/c/openocd/+/7137
Tested-by: jenkins
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Erhan Kurubas 2022-08-20 23:22:47 +03:00 committed by Antonio Borneo
parent 44e21b41df
commit f77c919cf4
1 changed files with 6 additions and 3 deletions

View File

@ -591,7 +591,7 @@ static int xtensa_write_dirty_registers(struct target *target)
unsigned int reg_list_size = xtensa->core_cache->num_regs;
bool preserve_a3 = false;
uint8_t a3_buf[4];
xtensa_reg_val_t a3, woe;
xtensa_reg_val_t a3 = 0, woe;
LOG_TARGET_DEBUG(target, "start");
@ -655,6 +655,8 @@ static int xtensa_write_dirty_registers(struct target *target)
xtensa_queue_exec_ins(xtensa, XT_INS_WSR(xtensa, XT_SR_DDR, XT_REG_A3));
xtensa_queue_dbg_reg_read(xtensa, NARADR_DDR, a3_buf);
res = jtag_execute_queue();
if (res != ERROR_OK)
return res;
xtensa_core_status_check(target);
a3 = buf_get_u32(a3_buf, 0, 32);
}
@ -2468,7 +2470,7 @@ static int xtensa_build_reg_cache(struct target *target)
LOG_TARGET_ERROR(target, "ERROR: Out of memory");
goto fail;
}
sprintf((char *)xtensa->empty_regs[i].name, "?0x%04x", i);
sprintf((char *)xtensa->empty_regs[i].name, "?0x%04x", i & 0x0000FFFF);
xtensa->empty_regs[i].size = 32;
xtensa->empty_regs[i].type = &xtensa_reg_type;
xtensa->empty_regs[i].value = calloc(1, 4 /*XT_REG_LEN*/); /* make Clang Static Analyzer happy */
@ -2526,6 +2528,7 @@ fail:
if (reg_list) {
for (unsigned int i = 0; i < reg_list_size; i++)
free(reg_list[i].value);
free(reg_list);
}
if (xtensa->empty_regs) {
for (unsigned int i = 0; i < xtensa->dbregs_num; i++) {
@ -2847,7 +2850,7 @@ int xtensa_init_arch_info(struct target *target, struct xtensa *xtensa,
for (enum xtensa_ar_scratch_set_e s = 0; s < XT_AR_SCRATCH_NUM; s++) {
xtensa->scratch_ars[s].chrval = calloc(8, sizeof(char));
if (!xtensa->scratch_ars[s].chrval) {
for (enum xtensa_ar_scratch_set_e f = s - 1; s >= 0; s--)
for (enum xtensa_ar_scratch_set_e f = 0; f < s; f++)
free(xtensa->scratch_ars[f].chrval);
free(xtensa->core_config);
LOG_ERROR("Xtensa scratch AR alloc failed\n");