aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2014-11-28 12:38:37 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2014-11-28 12:39:01 -0800
commit9e9b74fe465d95f1d827de1825a18c39810c0816 (patch)
tree4f89f8ad9d07bcd9c39604499dfd6736de6744b8
parentd94d592d2b76c2f0c4bc27ab74ff145ee1e390f5 (diff)
Clarified logic in remove_delimiter.
Motivated by warnings from clang static analyzer.
-rw-r--r--src/inlines.c16
1 files changed, 11 insertions, 5 deletions
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);