aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-02-05 20:36:21 +0100
committerMattias Andrée <maandree@kth.se>2023-02-05 20:36:21 +0100
commitb53e30ab104d3fd5431cfd9a2b8891dfcbe89d1e (patch)
tree4a50526c79231aa2033fda94a7b4ee9516b8df84
parentdraw_linear_bezier_reference: fix bounds checking error (diff)
downloadlibrifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket-b53e30ab104d3fd5431cfd9a2b8891dfcbe89d1e.tar.gz
librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket-b53e30ab104d3fd5431cfd9a2b8891dfcbe89d1e.tar.bz2
librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket-b53e30ab104d3fd5431cfd9a2b8891dfcbe89d1e.tar.xz
Fix warnings
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--draw_linear_bezier_reference.c81
-rw-r--r--librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h11
2 files changed, 64 insertions, 28 deletions
diff --git a/draw_linear_bezier_reference.c b/draw_linear_bezier_reference.c
index 451eb3a..a395c18 100644
--- a/draw_linear_bezier_reference.c
+++ b/draw_linear_bezier_reference.c
@@ -112,7 +112,7 @@ draw_linear_bezier_reference(RASTER *restrict raster, double x1, double y1, doub
#define CHECK_CELL(X, Y, AREA, SHADOW)\
do {\
- size_t i__ = (Y) * raster->width + (X);\
+ size_t i__ = (size_t)(Y) * raster->width + (size_t)(X);\
ASSERT(raster->cells[i__].cell_coverage == (AREA));\
ASSERT(raster->cells[i__].opposite_coverage == (SHADOW));\
raster->cells[i__].cell_coverage = 0;\
@@ -121,7 +121,7 @@ draw_linear_bezier_reference(RASTER *restrict raster, double x1, double y1, doub
#define SUB_CELL(X, Y, AREA, SHADOW)\
do {\
- size_t i__ = (Y) * raster->width + (X);\
+ size_t i__ = (size_t)(Y) * raster->width + (size_t)(X);\
raster->cells[i__].cell_coverage -= (AREA);\
raster->cells[i__].opposite_coverage -= (SHADOW);\
} while (0)
@@ -160,28 +160,31 @@ draw(double x1, double y1, double x2, double y2)
draw_linear_bezier_reference(raster, x1, y1, x2, y2);
alarm(0);
}
-#undef draw_linear_bezier_reference
-#define draw_linear_bezier_reference "use draw(double, double, double, double) instead"
static void
check_horizontal(void)
{
ssize_t y, x1, x2;
+ double fy, fx1, fx2;
for (y = -2; y < 12; y++) {
for (x1 = -2; x1 < 12; x1++) {
for (x2 = -2; x2 < 12; x2++) {
- draw(x1, y, x2, y);
+ fy = (double)y;
+ fx1 = (double)x1;
+ fx2 = (double)x2;
+
+ draw(fx1, fy, fx2, fy);
CHECK_ZEROED();
- draw(x1 + 0.25, y, x2 + 0.25, y);
+ draw(fx1 + 0.25, fy, fx2 + 0.25, fy);
CHECK_ZEROED();
- draw(x1, y + 0.25, x2, y + 0.25);
+ draw(fx1, fy + 0.25, fx2, fy + 0.25);
CHECK_ZEROED();
- draw(x1 + 0.25, y + 0.25, x2 + 0.25, y + 0.25);
+ draw(fx1 + 0.25, fy + 0.25, fx2 + 0.25, fy + 0.25);
CHECK_ZEROED();
}
}
@@ -194,13 +197,17 @@ check_vertical(void)
{
ssize_t x, y1, y2, i, ydir;
double yhit;
+ double fx, fy1, fy2;
for (x = -2; x < 12; x++) {
for (y1 = -2; y1 < 12; y1++) {
for (y2 = -2; y2 < 12; y2++) {
ydir = SIGNUM(y2 - y1);
+ fx = (double)x;
+ fy1 = (double)y1;
+ fy2 = (double)y2;
- draw(x, y1, x, y2);
+ draw(fx, fy1, fx, fy2);
for (i = 0; i < 10; i++) {
if (i < y1 && i < y2)
continue;
@@ -213,7 +220,7 @@ check_vertical(void)
}
CHECK_ZEROED();
- draw(x + 0.25, y1, x + 0.25, y2);
+ draw(fx + 0.25, fy1, fx + 0.25, fy2);
for (i = 0; i < 10; i++) {
if (i < y1 && i < y2)
continue;
@@ -226,7 +233,7 @@ check_vertical(void)
}
CHECK_ZEROED();
- draw(x, y1 + 0.25, x, y2 + 0.25);
+ draw(fx, fy1 + 0.25, fx, fy2 + 0.25);
for (i = 0; i < 10; i++) {
if (i < y1 + (y1 > y2) && i < y2 + (y2 > y1))
continue;
@@ -240,7 +247,7 @@ check_vertical(void)
}
CHECK_ZEROED();
- draw(x + 0.25, y1 + 0.25, x + 0.25, y2 + 0.25);
+ draw(fx + 0.25, fy1 + 0.25, fx + 0.25, fy2 + 0.25);
for (i = 0; i < 10; i++) {
if (i < y1 + (y1 > y2) && i < y2 + (y2 > y1))
continue;
@@ -262,15 +269,20 @@ check_vertical(void)
static void
check_11_diagonal(ssize_t xshift, ssize_t yshift)
{
- ssize_t i1, i2, i, imin, imax, idir, x, y;
+ ssize_t i1, i2, i, imin, imax, x, y;
+ double fi1, fi2, idir;
+ double fxshift = (double)xshift;
+ double fyshift = (double)yshift;
for (i1 = -2; i1 < 12; i1++) {
for (i2 = -2; i2 < 12; i2++) {
imin = i1 < i2 ? i1 : i2;
imax = i1 > i2 ? i1 : i2;
- idir = SIGNUM(i2 - i1);
+ fi1 = (double)i1;
+ fi2 = (double)i2;
+ idir = SIGNUM(fi2 - fi1);
- draw(i1 + xshift, i1 + yshift, i2 + xshift, i2 + yshift);
+ draw(fi1 + fxshift, fi1 + fyshift, fi2 + fxshift, fi2 + fyshift);
for (i = imin; i < imax; i++) {
x = i + xshift;
y = i + yshift;
@@ -285,7 +297,7 @@ check_11_diagonal(ssize_t xshift, ssize_t yshift)
}
CHECK_ZEROED();
- draw(i1 + xshift, i1 + yshift + 0.25, i2 + xshift, i2 + yshift + 0.25);
+ draw(fi1 + fxshift, fi1 + fyshift + 0.25, fi2 + fxshift, fi2 + fyshift + 0.25);
for (i = imin; i < imax; i++) {
x = i + xshift;
y = i + yshift;
@@ -310,7 +322,7 @@ check_11_diagonal(ssize_t xshift, ssize_t yshift)
}
CHECK_ZEROED();
- draw(i1 + xshift + 0.25, i1 + yshift, i2 + xshift + 0.25, i2 + yshift);
+ draw(fi1 + fxshift + 0.25, fi1 + fyshift, fi2 + fxshift + 0.25, fi2 + fyshift);
for (i = imin; i < imax; i++) {
x = i + xshift;
y = i + yshift;
@@ -335,7 +347,7 @@ check_11_diagonal(ssize_t xshift, ssize_t yshift)
}
CHECK_ZEROED();
- draw(i1 + xshift + 0.25, i1 + yshift + 0.25, i2 + xshift + 0.25, i2 + yshift + 0.25);
+ draw(fi1 + fxshift + 0.25, fi1 + fyshift + 0.25, fi2 + fxshift + 0.25, fi2 + fyshift + 0.25);
for (i = imin; i < imax; i++) {
x = i + xshift;
y = i + yshift;
@@ -367,15 +379,20 @@ check_11_diagonal(ssize_t xshift, ssize_t yshift)
static void
check_11_antidiagonal(ssize_t xshift, ssize_t yshift)
{
- ssize_t i1, i2, i, imin, imax, ydir, x, y;
+ ssize_t i1, i2, i, imin, imax, x, y;
+ double fi1, fi2, ydir;
+ double fxshift = (double)xshift;
+ double fyshift = (double)yshift;
for (i1 = -2; i1 < 12; i1++) {
for (i2 = -2; i2 < 12; i2++) {
imin = i1 < i2 ? i1 : i2;
imax = i1 > i2 ? i1 : i2;
- ydir = -SIGNUM(i2 - i1);
+ fi1 = (double)i1;
+ fi2 = (double)i2;
+ ydir = -SIGNUM(fi2 - fi1);
- draw(i1 + xshift, i2 + yshift, i2 + xshift, i1 + yshift);
+ draw(fi1 + fxshift, fi2 + fyshift, fi2 + fxshift, fi1 + fyshift);
for (i = imin; i < imax; i++) {
x = i + xshift;
y = imax - i + imin + yshift - 1;
@@ -390,7 +407,7 @@ check_11_antidiagonal(ssize_t xshift, ssize_t yshift)
}
CHECK_ZEROED();
- draw(i1 + xshift, i2 + yshift + 0.25, i2 + xshift, i1 + yshift + 0.25);
+ draw(fi1 + fxshift, fi2 + fyshift + 0.25, fi2 + fxshift, fi1 + fyshift + 0.25);
for (i = imin; i < imax; i++) {
x = i + xshift;
y = imax - i + imin + yshift - 1;
@@ -415,7 +432,7 @@ check_11_antidiagonal(ssize_t xshift, ssize_t yshift)
}
CHECK_ZEROED();
- draw(i1 + xshift + 0.25, i2 + yshift, i2 + xshift + 0.25, i1 + yshift);
+ draw(fi1 + fxshift + 0.25, fi2 + fyshift, fi2 + fxshift + 0.25, fi1 + fyshift);
for (i = imin; i < imax; i++) {
x = i + xshift;
y = imax - i + imin + yshift - 1;
@@ -440,7 +457,7 @@ check_11_antidiagonal(ssize_t xshift, ssize_t yshift)
}
CHECK_ZEROED();
- draw(i1 + xshift + 0.25, i2 + yshift + 0.25, i2 + xshift + 0.25, i1 + yshift + 0.25);
+ draw(fi1 + fxshift + 0.25, fi2 + fyshift + 0.25, fi2 + fxshift + 0.25, fi1 + fyshift + 0.25);
for (i = imin; i < imax; i++) {
x = i + xshift;
y = imax - i + imin + yshift - 1;
@@ -479,13 +496,21 @@ check_11_antidiagonal(ssize_t xshift, ssize_t yshift)
}
+static double
+frand(void)
+{
+ int i = rand();
+ return (double)i / (double)RAND_MAX;
+}
+
+
static void
try_random_line(void)
{
- double x1 = (double)rand() / (double)RAND_MAX;
- double y1 = (double)rand() / (double)RAND_MAX;
- double x2 = (double)rand() / (double)RAND_MAX;
- double y2 = (double)rand() / (double)RAND_MAX;
+ double x1 = frand();
+ double y1 = frand();
+ double x2 = frand();
+ double y2 = frand();
draw(x1, y1, x2, y2);
}
diff --git a/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h b/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h
index 747694b..87bdd70 100644
--- a/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h
+++ b/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h
@@ -7,6 +7,12 @@
#include <stddef.h>
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdocumentation"
+#endif
+
+
/**
* Object that the library draws on, is converted to
* an ink-level image using the `rtgrpblib_fill_shapes`
@@ -136,4 +142,9 @@ void rtgrpblib_draw_circular_arc(RTGRPBLIB_RASTER *restrict raster, /* needed fo
double semiwidth, double semiheight,
double start, double end);
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
#endif