cmark

My personal build of CMark ✏️

Commit
5c2f3341e3c129aeb27f70fe6ca9ed0fea8f2383
Parent
118ebb338840d67005ee57ec39060d2b68f4ec7c
Author
John MacFarlane <jgm@berkeley.edu>
Date

Print message to stderr when we abort due to memory demands.

Closes #188.

@nwellnhof - could you have a look and let me know if you think this is a bad idea or could be improved?

Diffstat

2 files changed, 12 insertions, 3 deletions

Status File Name N° Changes Insertions Deletions
Modified src/buffer.c 7 6 1
Modified src/cmark.c 8 6 2
diff --git a/src/buffer.c b/src/buffer.c
@@ -42,7 +42,12 @@ void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size) {
   if (target_size < buf->asize)
     return;
 
-  if (target_size > (bufsize_t)(INT32_MAX / 2))
+  if (target_size > (bufsize_t)(INT32_MAX / 2)) {
+    fprintf(stderr,
+      "[cmark] cmark_strbuf_grow requests buffer with size > %d, aborting\n",
+         (bufsize_t)(INT32_MAX / 2));
+    abort();
+  }
     abort();
 
   /* Oversize the buffer by 50% to guarantee amortized linear time
diff --git a/src/cmark.c b/src/cmark.c
@@ -12,15 +12,19 @@ const char *cmark_version_string() { return CMARK_VERSION_STRING; }
 
 static void *xcalloc(size_t nmem, size_t size) {
   void *ptr = calloc(nmem, size);
-  if (!ptr)
+  if (!ptr) {
+    fprintf(stderr, "[cmark] calloc returned null pointer, aborting\n");
     abort();
+  }
   return ptr;
 }
 
 static void *xrealloc(void *ptr, size_t size) {
   void *new_ptr = realloc(ptr, size);
-  if (!new_ptr)
+  if (!new_ptr) {
+    fprintf(stderr, "[cmark] realloc returned null pointer, aborting\n");
     abort();
+  }
   return new_ptr;
 }