Skip to content

Commit 00ae965

Browse files
committed
cortexm, cortexar: Report malloc failures in target_description
1 parent cc33cb4 commit 00ae965

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/target/cortexar.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,8 +1792,10 @@ static const char *cortexar_target_description(target_s *const target)
17921792
const size_t description_length =
17931793
cortexar_build_target_description(NULL, 0, target->target_options & TOPT_FLAVOUR_FLOAT) + 1U;
17941794
char *const description = malloc(description_length);
1795-
if (description)
1796-
(void)cortexar_build_target_description(
1797-
description, description_length, target->target_options & TOPT_FLAVOUR_FLOAT);
1795+
if (!description) { /* malloc failed: heap exhaustion */
1796+
DEBUG_ERROR("malloc: failed in %s\n", __func__);
1797+
return description;
1798+
}
1799+
cortexar_build_target_description(description, description_length, target->target_options & TOPT_FLAVOUR_FLOAT);
17981800
return description;
17991801
}

src/target/cortexm.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,14 @@ const char *cortexm_regs_description(target_s *target)
439439
const size_t description_length =
440440
(is_cortexmf ? create_tdesc_cortex_mf(NULL, 0) : create_tdesc_cortex_m(NULL, 0)) + 1U;
441441
char *const description = malloc(description_length);
442-
if (description) {
443-
if (is_cortexmf)
444-
create_tdesc_cortex_mf(description, description_length);
445-
else
446-
create_tdesc_cortex_m(description, description_length);
442+
if (!description) { /* malloc failed: heap exhaustion */
443+
DEBUG_ERROR("malloc: failed in %s\n", __func__);
444+
return description;
447445
}
446+
if (is_cortexmf)
447+
create_tdesc_cortex_mf(description, description_length);
448+
else
449+
create_tdesc_cortex_m(description, description_length);
448450
return description;
449451
}
450452

0 commit comments

Comments
 (0)