From: Matthew Fernandez Date: Fri, 14 Oct 2022 03:48:17 +0000 (-0700) Subject: JSON plugin stoj: remove static buffer X-Git-Tag: 7.0.1~2^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9fe05a8d8f0283d0a1d5078a9f9a210d48b28c4f;p=graphviz JSON plugin stoj: remove static buffer This removes some dynamic allocation, as well as making this function now thread safe. Note that the contained call to `latin1ToUTF8` still allocates. --- diff --git a/plugin/core/gvrender_core_json.c b/plugin/core/gvrender_core_json.c index 53d7b5dff..80a87d07f 100644 --- a/plugin/core/gvrender_core_json.c +++ b/plugin/core/gvrender_core_json.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -87,7 +86,6 @@ static void json_begin_graph(GVJ_t *job) static void stoj(char *ins, state_t *sp, GVJ_t *job) { char* s; char* input; - static agxbuf xb; char c; if (sp->isLatin) @@ -95,44 +93,42 @@ static void stoj(char *ins, state_t *sp, GVJ_t *job) { else input = ins; - if (xb.buf == NULL) - agxbinit(&xb, BUFSIZ, NULL); + gvputc(job, '"'); for (s = input; (c = *s); s++) { switch (c) { case '"' : - agxbput(&xb, "\\\""); + gvputs(job, "\\\""); break; case '\\' : - agxbput(&xb, "\\\\"); + gvputs(job, "\\\\"); break; case '/' : - agxbput(&xb, "\\/"); + gvputs(job, "\\/"); break; case '\b' : - agxbput(&xb, "\\b"); + gvputs(job, "\\b"); break; case '\f' : - agxbput(&xb, "\\f"); + gvputs(job, "\\f"); break; case '\n' : - agxbput(&xb, "\\n"); + gvputs(job, "\\n"); break; case '\r' : - agxbput(&xb, "\\r"); + gvputs(job, "\\r"); break; case '\t' : - agxbput(&xb, "\\t"); + gvputs(job, "\\t"); break; default : - agxbputc(&xb, c); + gvputc(job, c); break; } } - s = agxbuse(&xb); + gvputc(job, '"'); if (sp->isLatin) free (input); - gvprintf(job, "\"%s\"", s); } static void indent(GVJ_t * job, int level)