target/arc: fix clang static analyzer warnings 80/5480/2
authorEvgeniy Didin <didin@synopsys.com>
Fri, 28 Feb 2020 08:14:42 +0000 (11:14 +0300)
committerOleksij Rempel <linux@rempel-privat.de>
Sat, 29 Feb 2020 15:58:21 +0000 (15:58 +0000)
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>
src/target/arc.c
src/target/arc.h
src/target/arc_cmd.c
src/target/arc_jtag.c

index 45ef725dc0ca2f83ced8e9d3a7be096031ab6ab3..244dd5247624a40bf985b1bd6a4cfb6d61a6cfbf 100644 (file)
@@ -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);
                }
index 311648e15e93d9f5eee377ba6380e9e4a56c3704..af4149f978b7d7853f0ac920df7f84512d97a862 100644 (file)
@@ -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;
+       };
 };
 
 
index 3f6caf7512ccb587f1338f5d2b08eda4248b7597..3475762f4c9389c5b7e7a0d7afb8a450f68adf60 100644 (file)
@@ -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;
        }
 
index dd800a462e6af67b4359f6159cf967e52190dc6c..274d61f3a7ba8467802a1610919362ee9df2cdd4 100644 (file)
@@ -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);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)