summaryrefslogtreecommitdiff
path: root/src/inlines.c
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-10-24 19:15:59 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-10-24 19:15:59 -0700
commit2315882a431844394a2ec5300c03debf18713cb8 (patch)
treec71ea56cd678dbc8d2c50bc30d814015777d9367 /src/inlines.c
parent511e92f39fe9bdca51bea3ee0add95a6eca880f5 (diff)
parent0350e2dd936fbca4a911f096462e26af83469b81 (diff)
Merge branch 'master' of https://github.com/tchetch/stmd into tchetch-master
Conflicts: src/inlines.c
Diffstat (limited to 'src/inlines.c')
-rw-r--r--src/inlines.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/inlines.c b/src/inlines.c
index c95b46b..4744312 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -39,8 +39,10 @@ static unsigned char *bufdup(const unsigned char *buf)
if (buf) {
int len = strlen((char *)buf);
- new = malloc(len + 1);
- memcpy(new, buf, len + 1);
+ new = calloc(len + 1, sizeof(*new));
+ if(new != NULL) {
+ memcpy(new, buf, len + 1);
+ }
}
return new;
@@ -48,12 +50,14 @@ static unsigned char *bufdup(const unsigned char *buf)
static inline node_inl *make_link_(node_inl *label, unsigned char *url, unsigned char *title)
{
- node_inl* e = (node_inl*) malloc(sizeof(node_inl));
- e->tag = INL_LINK;
- e->content.linkable.label = label;
- e->content.linkable.url = url;
- e->content.linkable.title = title;
- e->next = NULL;
+ node_inl* e = calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->tag = INL_LINK;
+ e->content.linkable.label = label;
+ e->content.linkable.url = url;
+ e->content.linkable.title = title;
+ e->next = NULL;
+ }
return e;
}
@@ -75,29 +79,35 @@ inline static node_inl* make_link(node_inl* label, chunk url, chunk title)
inline static node_inl* make_inlines(int t, node_inl* contents)
{
- node_inl* e = (node_inl*) malloc(sizeof(node_inl));
- e->tag = t;
- e->content.inlines = contents;
- e->next = NULL;
+ node_inl * e = calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->tag = t;
+ e->content.inlines = contents;
+ e->next = NULL;
+ }
return e;
}
// Create an inline with a literal string value.
inline static node_inl* make_literal(int t, chunk s)
{
- node_inl* e = (node_inl*) malloc(sizeof(node_inl));
- e->tag = t;
- e->content.literal = s;
- e->next = NULL;
+ node_inl * e = calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->tag = t;
+ e->content.literal = s;
+ e->next = NULL;
+ }
return e;
}
// Create an inline with no value.
inline static node_inl* make_simple(int t)
{
- node_inl* e = (node_inl*) malloc(sizeof(node_inl));
- e->tag = t;
- e->next = NULL;
+ node_inl* e = calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->tag = t;
+ e->next = NULL;
+ }
return e;
}
@@ -382,6 +392,9 @@ cannotClose:
if (can_open)
{
istack = (inline_stack*)malloc(sizeof(inline_stack));
+ if (istack == NULL) {
+ return NULL;
+ }
istack->delim_count = numdelims;
istack->delim_char = c;
istack->first_inline = inl_text;