Skip to content

Commit

Permalink
cortexm, cortexar: Report malloc failures in target_description
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Aug 18, 2024
1 parent 0c4f304 commit 3886a7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/target/cortexar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1784,8 +1784,10 @@ static const char *cortexar_target_description(target_s *const target)
const size_t description_length =
cortexar_build_target_description(NULL, 0, target->target_options & TOPT_FLAVOUR_FLOAT) + 1U;
char *const description = malloc(description_length);
if (description)
(void)cortexar_build_target_description(
description, description_length, target->target_options & TOPT_FLAVOUR_FLOAT);
if (!description) { /* malloc failed: heap exhaustion */
DEBUG_ERROR("malloc: failed in %s\n", __func__);
return description;
}
cortexar_build_target_description(description, description_length, target->target_options & TOPT_FLAVOUR_FLOAT);
return description;
}
12 changes: 7 additions & 5 deletions src/target/cortexm.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,14 @@ const char *cortexm_regs_description(target_s *target)
const size_t description_length =
(is_cortexmf ? create_tdesc_cortex_mf(NULL, 0) : create_tdesc_cortex_m(NULL, 0)) + 1U;
char *const description = malloc(description_length);
if (description) {
if (is_cortexmf)
create_tdesc_cortex_mf(description, description_length);
else
create_tdesc_cortex_m(description, description_length);
if (!description) { /* malloc failed: heap exhaustion */
DEBUG_ERROR("malloc: failed in %s\n", __func__);
return description;
}
if (is_cortexmf)
create_tdesc_cortex_mf(description, description_length);
else
create_tdesc_cortex_m(description, description_length);
return description;
}

Expand Down

0 comments on commit 3886a7f

Please sign in to comment.