cmark

Unnamed repository; edit this file 'description' to name the repository.

commit 6baeaf39441895c0374974d96da84f2e3979cfb2
parent 1df1fd63e162314a62b512b29e27a30c67498028
Author: John MacFarlane <jgm@berkeley.edu>
Date:   Fri,  5 Dec 2014 10:02:04 -0800

Added CMARK_NODE_TYPE_NONE.

This is the return value of cmark_get_node_type when the argument
is a null pointer.  Avoids segfault.

Diffstat:
Mman/man3/cmark.3 | 4+++-
Msrc/cmark.h | 2++
Msrc/node.c | 7++++++-
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/man/man3/cmark.3 b/man/man3/cmark.3
@@ -1,4 +1,4 @@
-.TH cmark 3 "November 30, 2014" "LOCAL" "Library Functions Manual"
+.TH cmark 3 "December 05, 2014" "LOCAL" "Library Functions Manual"
 .SH NAME
 
 .B cmark
@@ -58,6 +58,8 @@ typedef enum {
 
 	CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT,
 	CMARK_NODE_LAST_INLINE  = CMARK_NODE_IMAGE,
+
+	CMARK_NODE_NONE = -1
 } cmark_node_type;
 .RE
 \f[]
diff --git a/src/cmark.h b/src/cmark.h
@@ -62,6 +62,8 @@ typedef enum {
 
 	CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT,
 	CMARK_NODE_LAST_INLINE  = CMARK_NODE_IMAGE,
+
+	CMARK_NODE_NONE = -1
 } cmark_node_type;
 
 
diff --git a/src/node.c b/src/node.c
@@ -77,7 +77,11 @@ cmark_node_free(cmark_node *node) {
 cmark_node_type
 cmark_node_get_type(cmark_node *node)
 {
-	return node->type;
+	if (node == NULL) {
+		return CMARK_NODE_NONE;
+	} else {
+		return node->type;
+	}
 }
 
 static const char*
@@ -103,6 +107,7 @@ S_type_string(cmark_node *node)
 	case CMARK_NODE_STRONG:        return "STRONG";
 	case CMARK_NODE_LINK:          return "LINK";
 	case CMARK_NODE_IMAGE:         return "IMAGE";
+	case CMARK_NODE_NONE:          return "NONE";
 	}
 
 	return "<unknown>";