From: glenlow Date: Sat, 2 Feb 2008 09:11:28 +0000 (+0000) Subject: gvRenderData outputs non-null terminated string and string length, reduced reallocations X-Git-Tag: LAST_LIBGRAPH~32^2~4782 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f68376c8f629115490697be179dc75ca7de3150a;p=graphviz gvRenderData outputs non-null terminated string and string length, reduced reallocations --- diff --git a/lib/gvc/gvc.c b/lib/gvc/gvc.c index b46d3f8bd..2087f5586 100644 --- a/lib/gvc/gvc.c +++ b/lib/gvc/gvc.c @@ -150,7 +150,7 @@ int gvRenderFilename(GVC_t *gvc, graph_t *g, char *format, char *filename) } /* Render layout in a specified format to a malloc'ed string */ -int gvRenderData(GVC_t *gvc, graph_t *g, char *format, char **result) +int gvRenderData(GVC_t *gvc, graph_t *g, char *format, char **result, unsigned int *length) { int rc; GVJ_t *job; @@ -172,14 +172,14 @@ int gvRenderData(GVC_t *gvc, graph_t *g, char *format, char **result) return -1; } -#define OUTPUT_DATA_INITIAL_ALLOCATION 1000 +/* page size on Linux, Mac OS X and Windows */ +#define OUTPUT_DATA_INITIAL_ALLOCATION 4096 if(!result || !(*result = malloc(OUTPUT_DATA_INITIAL_ALLOCATION))) { agerr(AGERR, "failure malloc'ing for result string"); return -1; } - **result = '\0'; job->output_data = *result; job->output_data_allocated = OUTPUT_DATA_INITIAL_ALLOCATION; job->output_data_position = 0; @@ -189,6 +189,7 @@ int gvRenderData(GVC_t *gvc, graph_t *g, char *format, char **result) gvdevice_finalize(job); *result = job->output_data; + *length = job->output_data_position; gvjobs_delete(gvc); return 0;