diff options
author | rodri <rgl@antares-labs.eu> | 2024-08-05 10:41:11 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-08-05 10:41:11 +0000 |
commit | 05ae0d42a944f6c7d940a5e58eb90b619dadbfdb (patch) | |
tree | f9b7e7ff1c189ded71d965bdc3eccf27ef26e462 | |
parent | c06379ee3aa51d3adf456c8d126feebd1da9de70 (diff) | |
download | libgraphics-05ae0d42a944f6c7d940a5e58eb90b619dadbfdb.tar.gz libgraphics-05ae0d42a944f6c7d940a5e58eb90b619dadbfdb.tar.bz2 libgraphics-05ae0d42a944f6c7d940a5e58eb90b619dadbfdb.zip |
fix a double-free. add a generic value-swapping macro.
-rw-r--r-- | clip.c | 20 | ||||
-rw-r--r-- | internal.h | 6 | ||||
-rw-r--r-- | render.c | 12 | ||||
-rw-r--r-- | util.c | 20 | ||||
-rw-r--r-- | vertex.c | 10 |
5 files changed, 13 insertions, 55 deletions
@@ -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){ @@ -45,7 +45,6 @@ void rmfbctl(Framebufctl*); /* vertex */ Vertex dupvertex(Vertex*); -void swapvertex(Vertex*, Vertex*); void lerpvertex(Vertex*, Vertex*, Vertex*, double); void berpvertex(Vertex*, Vertex*, Vertex*, Vertex*, Point3); void delvattrs(Vertex*); @@ -58,8 +57,6 @@ int rectclipline(Rectangle, Point*, Point*, Vertex*, Vertex*); /* util */ int min(int, int); int max(int, int); -void swapi(int*, int*); -void swappt(Point*, Point*); void memsetf(void*, float, usize); void memsetl(void*, ulong, usize); @@ -70,3 +67,6 @@ uvlong nanosec(void); #define getpixel(fb, p) (((fb)->cb)[Dx((fb)->r)*(p).y + (p).x]) /* void putpixel(Framebuf *fb, Point p, ulong c) */ #define putpixel(fb, p, c) (((fb)->cb)[Dx((fb)->r)*(p).y + (p).x] = (c)) + +/* void SWAP(type t, type *a, type *b) */ +#define SWAP(t, a, b) {t tmp; tmp = *(a); *(a) = *(b); *(b) = tmp;} @@ -135,14 +135,14 @@ rasterize(Rastertask *task) /* transpose the points */ if(abs(p0.x-p1.x) < abs(p0.y-p1.y)){ steep = 1; - swapi(&p0.x, &p0.y); - swapi(&p1.x, &p1.y); + SWAP(int, &p0.x, &p0.y); + SWAP(int, &p1.x, &p1.y); } /* make them left-to-right */ if(p0.x > p1.x){ - swappt(&p0, &p1); - swapvertex(&prim.v[0], &prim.v[1]); + SWAP(Point, &p0, &p1); + SWAP(Vertex, &prim.v[0], &prim.v[1]); } dp = subpt(p1, p0); @@ -155,7 +155,7 @@ rasterize(Rastertask *task) dplen = hypot(dp.x, dp.y); perc = dplen == 0? 0: hypot(Δp.x, Δp.y)/dplen; - if(steep) swapi(&p.x, &p.y); + if(steep) SWAP(int, &p.x, &p.y); z = flerp(prim.v[0].p.z, prim.v[1].p.z, perc); /* TODO get rid of the bounds check and make sure the clipping doesn't overflow */ @@ -176,7 +176,7 @@ rasterize(Rastertask *task) pixel(params->fb, p, c); delvattrs(&fsp.v); discard: - if(steep) swapi(&p.x, &p.y); + if(steep) SWAP(int, &p.x, &p.y); e += Δe; if(e > dp.x){ @@ -32,26 +32,6 @@ fmax(double a, double b) return a > b? a: b; } -void -swapi(int *a, int *b) -{ - int t; - - t = *a; - *a = *b; - *b = t; -} - -void -swappt(Point *a, Point *b) -{ - Point t; - - t = *a; - *a = *b; - *b = t; -} - Point2 modulapt2(Point2 a, Point2 b) { @@ -43,16 +43,6 @@ dupvertex(Vertex *v) return nv; } -void -swapvertex(Vertex *a, Vertex *b) -{ - Vertex t; - - t = *a; - *a = *b; - *b = t; -} - /* * linear attribute interpolation */ |