aboutsummaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authorEvgeniy Didin <didin@synopsys.com>2020-02-28 11:14:42 +0300
committerOleksij Rempel <linux@rempel-privat.de>2020-02-29 15:58:21 +0000
commit39d54ee96973d3e54a8722112cb9ca25245d01ad (patch)
tree2744b786e33b817a173fa8e1894cea45fd7e2a14 /src/target
parent9ee9bdd2f9e69df816d313d23b50a563c0869428 (diff)
target/arc: fix clang static analyzer warnings
Fixes: * Removed typo in *bitfields initializations. * Removed potentional memory leak allocating reg_data_type_struct_field/reg_data_type_flags_field objects. * Initialize buffers with "0" before usage in buf_set_u32(). * Removed memory leak in jim_arc_add_reg(). Change-Id: Iefde57cd4a48c4f3350c376475df8642607f52ff Signed-off-by: Evgeniy Didin <didin@synopsys.com> Reviewed-on: http://openocd.zylin.com/5480 Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Diffstat (limited to 'src/target')
-rw-r--r--src/target/arc.c4
-rw-r--r--src/target/arc.h4
-rw-r--r--src/target/arc_cmd.c7
-rw-r--r--src/target/arc_jtag.c6
4 files changed, 14 insertions, 7 deletions
diff --git a/src/target/arc.c b/src/target/arc.c
index 45ef725d..244dd524 100644
--- a/src/target/arc.c
+++ b/src/target/arc.c
@@ -1241,11 +1241,11 @@ static void arc_deinit_target(struct target *target)
/* Free arc-specific reg_data_types allocations*/
list_for_each_entry_safe_reverse(type, n, &arc->reg_data_types, list) {
if (type->data_type.type_class == REG_TYPE_CLASS_STRUCT) {
- free(type->data_type.reg_type_struct->fields);
+ free(type->reg_type_struct_field);
free(type->bitfields);
free(type);
} else if (type->data_type.type_class == REG_TYPE_CLASS_FLAGS) {
- free(type->data_type.reg_type_flags->fields);
+ free(type->reg_type_flags_field);
free(type->bitfields);
free(type);
}
diff --git a/src/target/arc.h b/src/target/arc.h
index 311648e1..af4149f9 100644
--- a/src/target/arc.h
+++ b/src/target/arc.h
@@ -61,6 +61,10 @@ struct arc_reg_data_type {
struct reg_data_type_struct data_type_struct;
char data_type_id[REG_TYPE_MAX_NAME_LENGTH];
struct arc_reg_bitfield *bitfields;
+ union {
+ struct reg_data_type_struct_field *reg_type_struct_field;
+ struct reg_data_type_flags_field *reg_type_flags_field;
+ };
};
diff --git a/src/target/arc_cmd.c b/src/target/arc_cmd.c
index 3f6caf75..3475762f 100644
--- a/src/target/arc_cmd.c
+++ b/src/target/arc_cmd.c
@@ -163,7 +163,8 @@ static int jim_arc_add_reg_type_flags(Jim_Interp *interp, int argc,
struct arc_reg_data_type *type = calloc(1, sizeof(*type));
struct reg_data_type_flags *flags = &type->data_type_flags;
struct reg_data_type_flags_field *fields = calloc(fields_sz, sizeof(*fields));
- struct arc_reg_bitfield *bitfields = calloc(fields_sz, sizeof(*type));
+ type->reg_type_flags_field = fields;
+ struct arc_reg_bitfield *bitfields = calloc(fields_sz, sizeof(*bitfields));
if (!(type && fields && bitfields)) {
Jim_SetResultFormatted(goi.interp, "Failed to allocate memory.");
goto fail;
@@ -528,7 +529,8 @@ static int jim_arc_add_reg_type_struct(Jim_Interp *interp, int argc,
struct arc_reg_data_type *type = calloc(1, sizeof(*type));
struct reg_data_type_struct *struct_type = &type->data_type_struct;
struct reg_data_type_struct_field *fields = calloc(fields_sz, sizeof(*fields));
- struct arc_reg_bitfield *bitfields = calloc(fields_sz, sizeof(*type));
+ type->reg_type_struct_field = fields;
+ struct arc_reg_bitfield *bitfields = calloc(fields_sz, sizeof(*bitfields));
if (!(type && fields && bitfields)) {
Jim_SetResultFormatted(goi.interp, "Failed to allocate memory.");
goto fail;
@@ -789,6 +791,7 @@ static int jim_arc_add_reg(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
target = get_current_target(ctx);
if (!target) {
Jim_SetResultFormatted(goi.interp, "No current target");
+ free_reg_desc(reg);
return JIM_ERR;
}
diff --git a/src/target/arc_jtag.c b/src/target/arc_jtag.c
index dd800a46..274d61f3 100644
--- a/src/target/arc_jtag.c
+++ b/src/target/arc_jtag.c
@@ -26,7 +26,7 @@ static void arc_jtag_enque_write_ir(struct arc_jtag *jtag_info, uint32_t
{
uint32_t current_instr;
struct jtag_tap *tap;
- uint8_t instr_buffer[sizeof(uint32_t)];
+ uint8_t instr_buffer[sizeof(uint32_t)] = {0};
assert(jtag_info);
assert(jtag_info->tap);
@@ -90,7 +90,7 @@ static void arc_jtag_enque_read_dr(struct arc_jtag *jtag_info, uint8_t *data,
static void arc_jtag_enque_write_dr(struct arc_jtag *jtag_info, uint32_t data,
tap_state_t end_state)
{
- uint8_t out_value[sizeof(uint32_t)];
+ uint8_t out_value[sizeof(uint32_t)] = {0};
assert(jtag_info);
assert(jtag_info->tap);
@@ -118,7 +118,7 @@ static void arc_jtag_enque_write_dr(struct arc_jtag *jtag_info, uint32_t data,
static void arc_jtag_enque_set_transaction(struct arc_jtag *jtag_info,
uint32_t new_trans, tap_state_t end_state)
{
- uint8_t out_value[sizeof(uint32_t)];
+ uint8_t out_value[sizeof(uint32_t)] = {0};
assert(jtag_info);
assert(jtag_info->tap);