#include "sashidown.h" #include #include #include char *cmark_markdown_to_html(const char *text, int len) { if (!text) return NULL; if (len < 0) len = (int)strlen(text); size_t in_len = (size_t)len; /* HTML typically expands; grow until parse fits (thread-safe, no static buf). */ size_t cap = in_len * 4 + 256; if (cap < 1024) cap = 1024; for (;;) { char *buf = (char *)malloc(cap); if (!buf) return NULL; size_t out_len = 0; if (sashidown_parse(text, in_len, buf, cap, &out_len) == 0) { char *fit = (char *)realloc(buf, out_len + 1); return fit ? fit : buf; } free(buf); if (cap > SIZE_MAX / 2) return NULL; size_t next = cap * 2; /* Bail if expansion is absurd relative to input. */ if (next > in_len * 64 + 4096) return NULL; cap = next; } } void sashidown_free(void *ptr) { free(ptr); }