Skip to content

Commit 3886a7f

Browse files
committed
cortexm, cortexar: Report malloc failures in target_description
1 parent 0c4f304 commit 3886a7f

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
@@ -1784,8 +1784,10 @@ static const char *cortexar_target_description(target_s *const target)
17841784
const size_t description_length =
17851785
cortexar_build_target_description(NULL, 0, target->target_options & TOPT_FLAVOUR_FLOAT) + 1U;
17861786
char *const description = malloc(description_length);
1787-
if (description)
1788-
(void)cortexar_build_target_description(
1789-
description, description_length, target->target_options & TOPT_FLAVOUR_FLOAT);
1787+
if (!description) { /* malloc failed: heap exhaustion */
1788+
DEBUG_ERROR("malloc: failed in %s\n", __func__);
1789+
return description;
1790+
}
1791+
cortexar_build_target_description(description, description_length, target->target_options & TOPT_FLAVOUR_FLOAT);
17901792
return description;
17911793
}

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)