summaryrefslogtreecommitdiff
path: root/src/inlines.c
diff options
context:
space:
mode:
authorPhil Turnbull <philipturnbull@github.com>2017-07-05 15:29:15 -0400
committerYuki Izumi <ashe@kivikakk.ee>2017-07-06 11:36:18 +1000
commitff28e0d00dbf8c4f84bbb379aa87257ae31cdd9d (patch)
tree48214456c5b9b45dae8d973f5a918862788dc21e /src/inlines.c
parent4b83812e6780e4a58669272a7426f1491711ca8c (diff)
Avoid memcpy'ing NULL pointers
A UBSAN warning can be triggered because the link title is an empty string: src/inlines.c:113:20: runtime error: null pointer passed as argument 2, which is declared to never be null which can be triggered by: ``` [f]:_ [f] ``` The length of the memcpy is zero so the NULL pointer is not dereferenced but it is still undefined behaviour.
Diffstat (limited to 'src/inlines.c')
-rw-r--r--src/inlines.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/inlines.c b/src/inlines.c
index f5b0621..b864e12 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -115,7 +115,8 @@ static cmark_chunk chunk_clone(cmark_mem *mem, cmark_chunk *src) {
c.len = len;
c.data = (unsigned char *)mem->calloc(len + 1, 1);
c.alloc = 1;
- memcpy(c.data, src->data, len);
+ if (len)
+ memcpy(c.data, src->data, len);
c.data[len] = '\0';
return c;