summaryrefslogtreecommitdiff
path: root/clip.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-08-05 10:41:11 +0000
committerrodri <rgl@antares-labs.eu>2024-08-05 10:41:11 +0000
commit05ae0d42a944f6c7d940a5e58eb90b619dadbfdb (patch)
treef9b7e7ff1c189ded71d965bdc3eccf27ef26e462 /clip.c
parentc06379ee3aa51d3adf456c8d126feebd1da9de70 (diff)
downloadlibgraphics-05ae0d42a944f6c7d940a5e58eb90b619dadbfdb.tar.gz
libgraphics-05ae0d42a944f6c7d940a5e58eb90b619dadbfdb.tar.bz2
libgraphics-05ae0d42a944f6c7d940a5e58eb90b619dadbfdb.zip
fix a double-free. add a generic value-swapping macro.
Diffstat (limited to 'clip.c')
-rw-r--r--clip.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/clip.c b/clip.c
index 94f84a6..aaa8754 100644
--- a/clip.c
+++ b/clip.c
@@ -34,16 +34,6 @@ addvert(Polygon *p, Vertex v)
}
static void
-swappoly(Polygon **a, Polygon **b)
-{
- Polygon *tmp;
-
- tmp = *a;
- *a = *b;
- *b = tmp;
-}
-
-static void
cleanpoly(Polygon *p)
{
int i;
@@ -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){