From 9e9b74fe465d95f1d827de1825a18c39810c0816 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 28 Nov 2014 12:38:37 -0800 Subject: Clarified logic in remove_delimiter. Motivated by warnings from clang static analyzer. --- src/inlines.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/inlines.c') diff --git a/src/inlines.c b/src/inlines.c index 49dc781..5c28436 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -294,13 +294,19 @@ static void print_delimiters(subject *subj) static void remove_delimiter(subject *subj, delimiter_stack *stack) { - if (stack->previous != NULL) { - stack->previous->next = stack->next; - } + if (stack == NULL) return; if (stack->next == NULL) { - // top of stack + // top of stack: + assert(stack == subj->delimiters); + if (stack->previous != NULL) { + stack->previous->next = NULL; + } subj->delimiters = stack->previous; - } else { + } else if (stack->previous == NULL) { + // bottom of stack, with something above it + stack->next->previous = NULL; + } else { // neither top nor bottom: + stack->previous->next = stack->next; stack->next->previous = stack->previous; } free(stack); -- cgit v1.2.3