diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-05-14 08:12:13 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-05-14 08:12:13 -0700 |
commit | 0e4769d5c1e254fa1747701d2da708d0cb61d0c3 (patch) | |
tree | 4a7b13b50456cc57743a1bedbbb5285605817479 /src/chunk.h | |
parent | 5ba5740f7e4404c0111a37f77db42c105740a6ff (diff) | |
parent | eada41977a4dc6da389d3bdefe7116ac2b1d75bd (diff) |
Merge pull request #38 from nwellnhof/chunks_for_links
Store link URL and title as cmark_chunk
Diffstat (limited to 'src/chunk.h')
-rw-r--r-- | src/chunk.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/chunk.h b/src/chunk.h index 54c4b16..3d6743c 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -7,6 +7,8 @@ #include "cmark_ctype.h" #include "buffer.h" +#define CMARK_CHUNK_EMPTY { NULL, 0, 0 } + typedef struct { unsigned char *data; int len; @@ -78,10 +80,17 @@ static inline void cmark_chunk_set_cstr(cmark_chunk *c, const char *str) if (c->alloc) { free(c->data); } - c->len = strlen(str); - c->data = (unsigned char *)malloc(c->len + 1); - c->alloc = 1; - memcpy(c->data, str, c->len + 1); + if (str == NULL) { + c->len = 0; + c->data = NULL; + c->alloc = 0; + } + else { + c->len = strlen(str); + c->data = (unsigned char *)malloc(c->len + 1); + c->alloc = 1; + memcpy(c->data, str, c->len + 1); + } } static inline cmark_chunk cmark_chunk_literal(const char *data) |