summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2018-07-29 11:21:46 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2018-07-29 11:22:37 +0100
commit90c270599b5b6c10ac06c37a0efb142d2d06bb3a (patch)
tree24acafc7c9fee6cb8e9000a3641e688a7ee46936
parentc22673e339c729016299000b844dead5b2bf0f25 (diff)
downloadlibnsfb-90c270599b5b6c10ac06c37a0efb142d2d06bb3a.tar.gz
libnsfb-90c270599b5b6c10ac06c37a0efb142d2d06bb3a.tar.bz2
Ploygon filling: Fix undefined behaviour.
src/plot/generic.c:243:10: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
-rw-r--r--src/plot/generic.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/plot/generic.c b/src/plot/generic.c
index 5479b2e..ea0bb04 100644
--- a/src/plot/generic.c
+++ b/src/plot/generic.c
@@ -128,6 +128,10 @@ static bool establish_crossing_value(int x, int y, int x0, int y0,
*/
static bool find_span(const int *p, int n, int x, int y, int *x0, int *x1)
{
+ enum {
+ NO_MIN = INT_MIN + 1,
+ NO_MAX = INT_MAX - 1,
+ };
int i;
int p_x0, p_y0;
int p_x1, p_y1;
@@ -137,16 +141,16 @@ static bool find_span(const int *p, int n, int x, int y, int *x0, int *x1)
bool crossing_value;
bool found_span_start = false;
- x0_min = x1_min = INT_MIN;
+ x0_min = x1_min = NO_MIN;
x0c = x1c = 0;
/* search row for next span, returning it if one exists */
do {
/* reset endpoint info, if valid span endpoints not found */
if (!found_span_start) {
- *x0 = INT_MAX;
+ *x0 = NO_MAX;
}
- *x1 = INT_MAX;
+ *x1 = NO_MAX;
/* search all lines in polygon */
for (i = 0; i < n; i = i + 2) {
@@ -242,7 +246,7 @@ static bool find_span(const int *p, int n, int x, int y, int *x0, int *x1)
x0_min = *x0 + 1;
x1_min = *x1 + 1;
- } while (*x1 != INT_MAX);
+ } while (*x1 != NO_MAX);
/* no spans found */
return false;