target/cortex: we remembered calloc() exists and saved another 16 bytes

This commit is contained in:
Mikaela Szekely 2022-08-23 08:16:24 -06:00 committed by Rachel Mant
parent 2cf1aff698
commit bc5a41530e
2 changed files with 5 additions and 10 deletions

View File

@ -257,10 +257,6 @@ static size_t create_tdesc_cortex_a(char *buffer, size_t max_len)
// that subtraction. // that subtraction.
size_t printsz = max_len; size_t printsz = max_len;
if (buffer != NULL)
memset(buffer, 0, max_len);
// Start with the "preamble", which is generic across ARM targets, // 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 // ...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. // 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, // 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 // 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. // 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) { for (size_t i = 0; i < ARRAY_SIZE(cortex_a_spr_names); ++i) {
gdb_reg_type_e type = cortex_a_spr_types[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, // Find the buffer size needed for the target description string we need to send to GDB,
// and then compute the string itself. // and then compute the string itself.
size_t size_needed = create_tdesc_cortex_a(NULL, 0) + 1; 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); create_tdesc_cortex_a(t->tdesc, size_needed);
} else { } else {
DEBUG_WARN("Cortex-A: target description already allocated before attach"); DEBUG_WARN("Cortex-A: target description already allocated before attach");

View File

@ -279,9 +279,6 @@ static size_t create_tdesc_cortex_m(char *buffer, size_t max_len)
// that subtraction. // that subtraction.
size_t printsz = max_len; size_t printsz = max_len;
if (buffer != NULL)
memset(buffer, 0, max_len);
// Start with the "preamble", which is generic across ARM targets, // Start with the "preamble", which is generic across ARM targets,
// ...save for one word, so we'll have to do the preamble in halves. // ...save for one word, so we'll have to do the preamble in halves.
total += snprintf(buffer, printsz, 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. // These special purpose registers are a little more complicated.
// Some of them have different bitsizes, specified types, or specified save-restore values. // Some of them have different bitsizes, specified types, or specified save-restore values.
// We'll use the 'associative arrays' defined for those 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) { for (size_t i = 0; i < ARRAY_SIZE(cortex_m_spr_names); ++i) {
if (max_len != 0) if (max_len != 0)
@ -748,11 +746,11 @@ bool cortexm_attach(target *t)
size_t size_needed; size_t size_needed;
if (!is_cortexmf) { if (!is_cortexmf) {
size_needed = create_tdesc_cortex_m(NULL, 0) + 1; 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); create_tdesc_cortex_m(t->tdesc, size_needed);
} else { } else {
size_needed = create_tdesc_cortex_mf(NULL, 0) + 1; 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); create_tdesc_cortex_mf(t->tdesc, size_needed);
} }
} else { } else {