From 9d0de94005f01bc934533351b7778704dc4e05ee Mon Sep 17 00:00:00 2001 From: david parsons Date: Sat, 21 Jan 2017 23:57:11 -0800 Subject: [PATCH] In mkd_toc(), take the hijack-the-T() hack out and strdup() the generated toc into the target pointer. --- toc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/toc.c b/toc.c index 31d827f..09ad915 100644 --- a/toc.c +++ b/toc.c @@ -81,16 +81,12 @@ mkd_toc(Document *p, char **doc) } if ( (size = S(res)) > 0 ) { + /* null-terminate & strdup into a free()able memory chunk + */ EXPAND(res) = 0; - /* HACK ALERT! HACK ALERT! HACK ALERT! */ - *doc = T(res); /* we know that a T(Cstring) is a character pointer - * so we can simply pick it up and carry it away, - * leaving the husk of the Ctring on the stack - * END HACK ALERT - */ + *doc = strdup(T(res)); } - else - DELETE(res); + DELETE(res); return size; }