diff --git a/src/target/cortexa.c b/src/target/cortexa.c index 172f44f..1d0ec79 100644 --- a/src/target/cortexa.c +++ b/src/target/cortexa.c @@ -257,10 +257,6 @@ static size_t create_tdesc_cortex_a(char *buffer, size_t max_len) // that subtraction. size_t printsz = max_len; - - if (buffer != NULL) - memset(buffer, 0, max_len); - // Start with the "preamble", which is generic across ARM targets, // ...save for one word, so we'll have to do the preamble in halves, and then we'll // follow it with the GDB ARM Core feature tag. @@ -284,6 +280,7 @@ static size_t create_tdesc_cortex_a(char *buffer, size_t max_len) // Some of them have different types specified, however unlike the Cortex-M SPRs, // all of the Cortex-A target description SPRs have the same bitsize, and none of them // have a specified save-restore value. So we only need one "associative array" here. + // NOTE: unlike the other loops, this loop uses a size_t for its counter, as it's used to index into arrays. for (size_t i = 0; i < ARRAY_SIZE(cortex_a_spr_names); ++i) { gdb_reg_type_e type = cortex_a_spr_types[i]; @@ -531,7 +528,7 @@ bool cortexa_attach(target *t) // Find the buffer size needed for the target description string we need to send to GDB, // and then compute the string itself. size_t size_needed = create_tdesc_cortex_a(NULL, 0) + 1; - t->tdesc = malloc(size_needed); + t->tdesc = calloc(1, size_needed); create_tdesc_cortex_a(t->tdesc, size_needed); } else { DEBUG_WARN("Cortex-A: target description already allocated before attach"); diff --git a/src/target/cortexm.c b/src/target/cortexm.c index c6d751c..917da0d 100644 --- a/src/target/cortexm.c +++ b/src/target/cortexm.c @@ -279,9 +279,6 @@ static size_t create_tdesc_cortex_m(char *buffer, size_t max_len) // that subtraction. size_t printsz = max_len; - if (buffer != NULL) - memset(buffer, 0, max_len); - // Start with the "preamble", which is generic across ARM targets, // ...save for one word, so we'll have to do the preamble in halves. total += snprintf(buffer, printsz, @@ -305,6 +302,7 @@ static size_t create_tdesc_cortex_m(char *buffer, size_t max_len) // These special purpose registers are a little more complicated. // Some of them have different bitsizes, specified types, or specified save-restore values. // We'll use the 'associative arrays' defined for those values. + // NOTE: unlike the other loops, this loop uses a size_t for its counter, as it's used to index into arrays. for (size_t i = 0; i < ARRAY_SIZE(cortex_m_spr_names); ++i) { if (max_len != 0) @@ -748,11 +746,11 @@ bool cortexm_attach(target *t) size_t size_needed; if (!is_cortexmf) { size_needed = create_tdesc_cortex_m(NULL, 0) + 1; - t->tdesc = malloc(size_needed); + t->tdesc = calloc(1, size_needed); create_tdesc_cortex_m(t->tdesc, size_needed); } else { size_needed = create_tdesc_cortex_mf(NULL, 0) + 1; - t->tdesc = malloc(size_needed); + t->tdesc = calloc(1, size_needed); create_tdesc_cortex_mf(t->tdesc, size_needed); } } else {