summaryrefslogtreecommitdiff
path: root/src/chunk.h
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2016-05-24 15:50:44 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2016-06-06 15:39:05 -0700
commit42b07cc9c8d2e6251d190e5ea0d13fd66cb51e6d (patch)
tree493ffc6b16278c54da28645d96a9359717625576 /src/chunk.h
parent0eafc0af940646ab581e47e63090c1692a3525aa (diff)
cmake: Global handler for OOM situations
Diffstat (limited to 'src/chunk.h')
-rw-r--r--src/chunk.h13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/chunk.h b/src/chunk.h
index 234a4f3..acceaa1 100644
--- a/src/chunk.h
+++ b/src/chunk.h
@@ -4,6 +4,7 @@
#include <string.h>
#include <stdlib.h>
#include <assert.h>
+#include "memory.h"
#include "cmark_ctype.h"
#include "buffer.h"
@@ -61,13 +62,11 @@ static CMARK_INLINE const char *cmark_chunk_to_cstr(cmark_chunk *c) {
if (c->alloc) {
return (char *)c->data;
}
- str = (unsigned char *)malloc(c->len + 1);
- if (str != NULL) {
- if (c->len > 0) {
- memcpy(str, c->data, c->len);
- }
- str[c->len] = 0;
+ str = (unsigned char *)cmark_calloc(c->len + 1, 1);
+ if (c->len > 0) {
+ memcpy(str, c->data, c->len);
}
+ str[c->len] = 0;
c->data = str;
c->alloc = 1;
@@ -84,7 +83,7 @@ static CMARK_INLINE void cmark_chunk_set_cstr(cmark_chunk *c, const char *str) {
c->alloc = 0;
} else {
c->len = strlen(str);
- c->data = (unsigned char *)malloc(c->len + 1);
+ c->data = (unsigned char *)cmark_calloc(c->len + 1, 1);
c->alloc = 1;
memcpy(c->data, str, c->len + 1);
}