From 05ae0d42a944f6c7d940a5e58eb90b619dadbfdb Mon Sep 17 00:00:00 2001 From: rodri Date: Mon, 5 Aug 2024 10:41:11 +0000 Subject: fix a double-free. add a generic value-swapping macro. --- clip.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'clip.c') diff --git a/clip.c b/clip.c index 94f84a6..aaa8754 100644 --- a/clip.c +++ b/clip.c @@ -33,16 +33,6 @@ addvert(Polygon *p, Vertex v) return p->n; } -static void -swappoly(Polygon **a, Polygon **b) -{ - Polygon *tmp; - - tmp = *a; - *a = *b; - *b = tmp; -} - static void cleanpoly(Polygon *p) { @@ -128,7 +118,7 @@ allin: } cleanpoly(Vin); if(j < 6-1) - swappoly(&Vin, &Vout); + SWAP(Polygon*, &Vin, &Vout); } if(Vout->n < 2) @@ -213,8 +203,6 @@ adjustverts(Point *p0, Point *p1, Vertex *v0, Vertex *v1) perc = len == 0? 0: hypot(Δp.x, Δp.y)/len; lerpvertex(&v[1], v0, v1, perc); - delvattrs(v0); - delvattrs(v1); *v0 = dupvertex(&v[0]); *v1 = dupvertex(&v[1]); } @@ -244,9 +232,9 @@ rectclipline(Rectangle r, Point *p0, Point *p1, Vertex *v0, Vertex *v1) return -1; if(ptisinside(code0)){ - swappt(p0, p1); - swapi(&code0, &code1); - swapvertex(v0, v1); + SWAP(Point, p0, p1); + SWAP(int, &code0, &code1); + SWAP(Vertex, v0, v1); } if(code0 & CLIPL){ -- cgit v1.2.3