summaryrefslogtreecommitdiff
path: root/src/chunk.h
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2015-05-09 16:30:50 +0200
committerNick Wellnhofer <wellnhofer@aevum.de>2015-05-14 14:36:01 +0200
commiteada41977a4dc6da389d3bdefe7116ac2b1d75bd (patch)
tree1122a5dc7ee59a033495ef164f23529902739954 /src/chunk.h
parentda23f80b53d47c76a85ba163cb0fb426050f3738 (diff)
Allow NULL value in string setters
Supersedes pull request #34.
Diffstat (limited to 'src/chunk.h')
-rw-r--r--src/chunk.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/chunk.h b/src/chunk.h
index 8b4333a..3d6743c 100644
--- a/src/chunk.h
+++ b/src/chunk.h
@@ -80,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)