From 433ba6e4d5da6c4b81ba1e4d056cbe12a539e34d Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 1 Jan 2023 18:47:13 -0800 Subject: [PATCH] core plugin mp_bezier: use an agxbuf to simplify some code Gitlab: #1950 --- plugin/core/gvrender_core_mp.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/plugin/core/gvrender_core_mp.c b/plugin/core/gvrender_core_mp.c index 0c7196353..4ba75f367 100644 --- a/plugin/core/gvrender_core_mp.c +++ b/plugin/core/gvrender_core_mp.c @@ -311,21 +311,14 @@ static void mp_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start, int cap_style = 0; int forward_arrow = 0; int backward_arrow = 0; - int npoints = n; int i; pointf pf, V[4]; point p; int j, step; int count = 0; - int size; - char *buffer; - char *buf; - buffer = - malloc((npoints + 1) * (BEZIERSUBDIVISION + - 1) * 20 * sizeof(char)); - buf = buffer; + agxbuf buf = {0}; mp_line_style(obj, &line_style, &style_val); @@ -344,8 +337,7 @@ static void mp_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start, /* Write first point in line */ count++; PF2P(A[0], p); - size = sprintf(buf, " %d %d", p.x, p.y); - buf += size; + agxbprint(&buf, " %d %d", p.x, p.y); /* write subsequent points */ for (i = 0; i + 3 < n; i += 3) { V[0] = V[3]; @@ -357,8 +349,7 @@ static void mp_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start, count++; pf = Bezier (V, 3, (double) step / BEZIERSUBDIVISION, NULL, NULL); PF2P(pf, p); - size = sprintf(buf, " %d %d", p.x, p.y); - buf += size; + agxbprint(&buf, " %d %d", p.x, p.y); } } @@ -374,8 +365,8 @@ static void mp_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start, area_fill, style_val, cap_style, forward_arrow, backward_arrow, count); - gvprintf(job, " %s\n", buffer); /* print points */ - free(buffer); + gvprintf(job, " %s\n", agxbuse(&buf)); /* print points */ + agxbfree(&buf); for (i = 0; i < count; i++) { gvprintf(job, " %d", i % (count + 1) ? 1 : 0); /* -1 on all */ } -- 2.40.0