cmark

Unnamed repository; edit this file 'description' to name the repository.

commit 68a3f24d93ed63fd1545c691442d69630649eadb
parent b0a4cfa36e99c27dd2b20be8f8888fa7721bad58
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Date:   Sun, 19 Jan 2020 01:22:17 +0100

Use C string instead of chunk in renderer

Fix another place where an "allocated" cmark_chunk was used.

Diffstat:
Msrc/render.c | 19+++++++++++--------
Msrc/render.h | 1-
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/render.c b/src/render.c
@@ -1,10 +1,10 @@
 #include <stdlib.h>
 #include "buffer.h"
-#include "chunk.h"
 #include "cmark.h"
 #include "utf8.h"
 #include "render.h"
 #include "node.h"
+#include "cmark_ctype.h"
 
 static CMARK_INLINE void S_cr(cmark_renderer *renderer) {
   if (renderer->need_cr < 1) {
@@ -26,7 +26,6 @@ static void S_out(cmark_renderer *renderer, const char *source, bool wrap,
   int i = 0;
   int last_nonspace;
   int len;
-  cmark_chunk remainder = cmark_chunk_literal("");
   int k = renderer->buffer->size - 1;
 
   wrap = wrap && !renderer->no_linebreaks;
@@ -112,18 +111,22 @@ static void S_out(cmark_renderer *renderer, const char *source, bool wrap,
         !renderer->begin_line && renderer->last_breakable > 0) {
 
       // copy from last_breakable to remainder
-      cmark_chunk_set_cstr(renderer->mem, &remainder,
-                           (char *)renderer->buffer->ptr +
-                               renderer->last_breakable + 1);
+      unsigned char *src = renderer->buffer->ptr +
+                           renderer->last_breakable + 1;
+      bufsize_t remainder_len = renderer->buffer->size -
+                                renderer->last_breakable - 1;
+      unsigned char *remainder =
+          (unsigned char *)renderer->mem->realloc(NULL, remainder_len);
+      memcpy(remainder, src, remainder_len);
       // truncate at last_breakable
       cmark_strbuf_truncate(renderer->buffer, renderer->last_breakable);
       // add newline, prefix, and remainder
       cmark_strbuf_putc(renderer->buffer, '\n');
       cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
                        renderer->prefix->size);
-      cmark_strbuf_put(renderer->buffer, remainder.data, remainder.len);
-      renderer->column = renderer->prefix->size + remainder.len;
-      cmark_chunk_free(renderer->mem, &remainder);
+      cmark_strbuf_put(renderer->buffer, remainder, remainder_len);
+      renderer->column = renderer->prefix->size + remainder_len;
+      renderer->mem->free(remainder);
       renderer->last_breakable = 0;
       renderer->begin_line = false;
       renderer->begin_content = false;
diff --git a/src/render.h b/src/render.h
@@ -7,7 +7,6 @@ extern "C" {
 
 #include <stdlib.h>
 #include "buffer.h"
-#include "chunk.h"
 
 typedef enum { LITERAL, NORMAL, TITLE, URL } cmark_escaping;