cmark

My personal build of CMark ✏️

Commit
9e9b74fe465d95f1d827de1825a18c39810c0816
Parent
d94d592d2b76c2f0c4bc27ab74ff145ee1e390f5
Author
John MacFarlane <fiddlosopher@gmail.com>
Date

Clarified logic in remove_delimiter.

Motivated by warnings from clang static analyzer.

Diffstat

1 file changed, 11 insertions, 5 deletions

Status File Name N° Changes Insertions Deletions
Modified src/inlines.c 16 11 5
diff --git 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);