summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2020-01-19 01:22:17 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2020-01-23 08:25:54 -0800
commit68a3f24d93ed63fd1545c691442d69630649eadb (patch)
treefdf98d29c556ba152cd9ad00e81deb52ad9fefc4
parentb0a4cfa36e99c27dd2b20be8f8888fa7721bad58 (diff)
Use C string instead of chunk in renderer
Fix another place where an "allocated" cmark_chunk was used.
-rw-r--r--src/render.c19
-rw-r--r--src/render.h1
2 files changed, 11 insertions, 9 deletions
diff --git a/src/render.c b/src/render.c
index f374b1c..c076e17 100644
--- 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
index 0575340..15f6c2c 100644
--- 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;