diff --git a/src/target/cortexar.c b/src/target/cortexar.c index 3982e983454..0ab91a46c17 100644 --- a/src/target/cortexar.c +++ b/src/target/cortexar.c @@ -1864,8 +1864,9 @@ 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__); + else + cortexar_build_target_description(description, description_length, target->target_options & TOPT_FLAVOUR_FLOAT); return description; } diff --git a/src/target/cortexm.c b/src/target/cortexm.c index 77ca32c7d4c..8460113bc0c 100644 --- a/src/target/cortexm.c +++ b/src/target/cortexm.c @@ -1521,7 +1521,9 @@ static const char *cortexm_target_description(target_s *const target) { const size_t description_length = cortexm_build_target_description(NULL, 0, target->target_options) + 1U; char *const description = malloc(description_length); - if (description) + if (!description) /* malloc failed: heap exhaustion */ + DEBUG_ERROR("malloc: failed in %s\n", __func__); + else cortexm_build_target_description(description, description_length, target->target_options); return description; } diff --git a/src/target/riscv_debug.c b/src/target/riscv_debug.c index 14d28b35926..2a03989fc84 100644 --- a/src/target/riscv_debug.c +++ b/src/target/riscv_debug.c @@ -1287,7 +1287,9 @@ static const char *riscv_target_description(target_s *const target) const size_t description_length = riscv_build_target_description(NULL, 0, hart->address_width, hart->extensions) + 1U; char *const description = malloc(description_length); - if (description) - (void)riscv_build_target_description(description, description_length, hart->address_width, hart->extensions); + if (!description) /* malloc failed: heap exhaustion */ + DEBUG_ERROR("malloc: failed in %s\n", __func__); + else + riscv_build_target_description(description, description_length, hart->address_width, hart->extensions); return description; }