From 3a578e190ff9aea56d3353f4ce3e423c23e7a98f Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 26 Oct 2024 19:15:17 +0100 Subject: [PATCH] Assert success of alloc in deep_copy_* loops Returning false here would leave the destination sequence in an invalid state and may lead to leaked memory; until this is solved properly it is safer to assert(). --- lib/desugar.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/desugar.c b/lib/desugar.c index 4596fcc..4508dc1 100644 --- a/lib/desugar.c +++ b/lib/desugar.c @@ -46,10 +46,8 @@ static bool deep_copy_sequence(parse_sequence_t *dst, parse_sequence_t *src) if (NULL == dst->contents) return false; - for (int i = 0; i < dst->count; ++i) { - if (!deep_copy_term(&dst->contents[i], &src->contents[i])) - return false; - } + for (int i = 0; i < dst->count; ++i) + assert(deep_copy_term(&dst->contents[i], &src->contents[i])); return true; } @@ -68,9 +66,8 @@ static bool deep_copy_term(parse_term_t *dst, parse_term_t *src) return false; for (int i = 0; i < dst->subexpr.count; ++i) { - if (!deep_copy_sequence( - &dst->subexpr.contents[i], &src->subexpr.contents[i])) - return false; + assert(deep_copy_sequence( + &dst->subexpr.contents[i], &src->subexpr.contents[i])); } }