From b419cee2dac6d29b2e4f6b8f8a5f8ebc95aa785e Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Tue, 23 Aug 2022 21:15:09 -0700 Subject: [PATCH] use 'gv_strdup' instead of 'strdup' in 'Show_boxes' This fixes some unchecked allocation failures. --- lib/common/routespl.c | 35 ++++++++++++++++++----------------- lib/common/splines.c | 7 ++++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/common/routespl.c b/lib/common/routespl.c index e9a228434..5746b2e79 100644 --- a/lib/common/routespl.c +++ b/lib/common/routespl.c @@ -10,6 +10,7 @@ #include "config.h" #include +#include #include #include #include @@ -89,16 +90,16 @@ static void psprintspline(Ppolyline_t spl) Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); li = Show_cnt+1; - Show_boxes[li++] = strdup ("%%!"); - Show_boxes[li++] = strdup ("%% spline"); - Show_boxes[li++] = strdup ("gsave 1 0 0 setrgbcolor newpath"); + Show_boxes[li++] = gv_strdup("%%!"); + Show_boxes[li++] = gv_strdup("%% spline"); + Show_boxes[li++] = gv_strdup("gsave 1 0 0 setrgbcolor newpath"); for (i = 0; i < spl.pn; i++) { agxbuf buf = {0}; agxbprint(&buf, "%f %f %s", spl.ps[i].x, spl.ps[i].y, i == 0 ? "moveto" : (i % 3 == 0 ? "curveto" : "")); Show_boxes[li++] = agxbdisown(&buf); } - Show_boxes[li++] = strdup ("stroke grestore"); + Show_boxes[li++] = gv_strdup("stroke grestore"); Show_cnt = newcnt; Show_boxes[Show_cnt+1] = NULL; } @@ -110,16 +111,16 @@ static void psprintline(Ppolyline_t pl) Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); li = Show_cnt+1; - Show_boxes[li++] = strdup ("%%!"); - Show_boxes[li++] = strdup ("%% line"); - Show_boxes[li++] = strdup ("gsave 0 0 1 setrgbcolor newpath"); + Show_boxes[li++] = gv_strdup("%%!"); + Show_boxes[li++] = gv_strdup("%% line"); + Show_boxes[li++] = gv_strdup("gsave 0 0 1 setrgbcolor newpath"); for (i = 0; i < pl.pn; i++) { agxbuf buf = {0}; agxbprint(&buf, "%f %f %s", pl.ps[i].x, pl.ps[i].y, i == 0 ? "moveto" : "lineto"); Show_boxes[li++] = agxbdisown(&buf); } - Show_boxes[li++] = strdup ("stroke grestore"); + Show_boxes[li++] = gv_strdup("stroke grestore"); Show_cnt = newcnt; Show_boxes[Show_cnt+1] = NULL; } @@ -133,8 +134,8 @@ static void psprintpoly(Ppoly_t p) Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); li = Show_cnt+1; - Show_boxes[li++] = strdup ("%% poly list"); - Show_boxes[li++] = strdup ("gsave 0 1 0 setrgbcolor"); + Show_boxes[li++] = gv_strdup("%% poly list"); + Show_boxes[li++] = gv_strdup("gsave 0 1 0 setrgbcolor"); for (bi = 0; bi < p.pn; bi++) { tl.x = (int)p.ps[bi].x; tl.y = (int)p.ps[bi].y; @@ -146,7 +147,7 @@ static void psprintpoly(Ppoly_t p) agxbprint(&buf, "%s%d %d %d %d makevec", pfx, tl.x, tl.y, hd.x, hd.y); Show_boxes[li++] = agxbdisown(&buf); } - Show_boxes[li++] = strdup ("grestore"); + Show_boxes[li++] = gv_strdup("grestore"); Show_cnt = newcnt; Show_boxes[Show_cnt+1] = NULL; @@ -160,8 +161,8 @@ static void psprintboxes(int boxn, boxf* boxes) Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); li = Show_cnt+1; - Show_boxes[li++] = strdup ("%% box list"); - Show_boxes[li++] = strdup ("gsave 0 1 0 setrgbcolor"); + Show_boxes[li++] = gv_strdup("%% box list"); + Show_boxes[li++] = gv_strdup("gsave 0 1 0 setrgbcolor"); for (bi = 0; bi < boxn; bi++) { ll = boxes[bi].LL, ur = boxes[bi].UR; agxbuf buf = {0}; @@ -173,9 +174,9 @@ static void psprintboxes(int boxn, boxf* boxes) Show_boxes[li++] = agxbdisown(&buf); agxbprint(&buf, "%.0f %.0f lineto", ur.x, ll.y); Show_boxes[li++] = agxbdisown(&buf); - Show_boxes[li++] = strdup ("closepath stroke"); + Show_boxes[li++] = gv_strdup("closepath stroke"); } - Show_boxes[li++] = strdup ("grestore"); + Show_boxes[li++] = gv_strdup("grestore"); Show_cnt = newcnt; Show_boxes[Show_cnt+1] = NULL; @@ -187,9 +188,9 @@ static void psprintinit (int begin) Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); if (begin) - Show_boxes[1+Show_cnt] = strdup ("dbgstart"); + Show_boxes[1+Show_cnt] = gv_strdup("dbgstart"); else - Show_boxes[1+Show_cnt] = strdup ("grestore"); + Show_boxes[1+Show_cnt] = gv_strdup("grestore"); Show_cnt = newcnt; Show_boxes[Show_cnt+1] = NULL; } diff --git a/lib/common/splines.c b/lib/common/splines.c index e81a3880f..564c4a116 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -36,14 +37,14 @@ static void showPoints(pointf ps[], int pn) Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); li = Show_cnt+1; - Show_boxes[li++] = strdup ("%% self list"); - Show_boxes[li++] = strdup ("dbgstart"); + Show_boxes[li++] = gv_strdup("%% self list"); + Show_boxes[li++] = gv_strdup("dbgstart"); for (bi = 0; bi < pn; bi++) { agxbuf buf = {0}; agxbprint(&buf, "%.5g %.5g point", ps[bi].x, ps[bi].y); Show_boxes[li++] = agxbdisown(&buf); } - Show_boxes[li++] = strdup ("grestore"); + Show_boxes[li++] = gv_strdup("grestore"); Show_cnt = newcnt; Show_boxes[Show_cnt+1] = NULL; -- 2.40.0