From a7a180366686298fa7f7aae686152e5a759d3a89 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Thu, 16 Feb 2012 01:08:05 +0100 Subject: Take care of boundary conditions in ps function evaluation. Floating point numbers are now clamped, division by zero is approximated by minimum or maximum value and NaN results in 1.0. --- fitz/fitz.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'fitz') diff --git a/fitz/fitz.h b/fitz/fitz.h index 594bc4e9..d80204f0 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -15,7 +15,7 @@ #include #include #include /* INT_MAX & co */ -#include /* FLT_EPSILON */ +#include /* FLT_EPSILON, FLT_MAX & co */ #include /* O_RDONLY & co */ #include @@ -46,6 +46,7 @@ #define MIN(a,b) ( (a) < (b) ? (a) : (b) ) #define MAX(a,b) ( (a) > (b) ? (a) : (b) ) #define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) ) +#define DIV_BY_ZERO(a, b, min, max) (((a) < 0) ^ ((b) < 0) ? (min) : (max)) /* * Some differences in libc can be smoothed over @@ -62,6 +63,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz); #define snprintf _snprintf +#define isnan _isnan #else /* Unix or close enough */ -- cgit v1.2.3 From 71e34dd2493b41836db5a9b539ac7ab38e18ddd5 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 19 Feb 2012 18:06:50 +0100 Subject: Clamp real numbers when parsing. Instead of returning in 1.0 for underflow/overflow, return minimum value for underflow and maximum value for overflow. NaN returns 1.0. --- fitz/base_string.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'fitz') diff --git a/fitz/base_string.c b/fitz/base_string.c index dd9f8ea2..2c8877c8 100644 --- a/fitz/base_string.c +++ b/fitz/base_string.c @@ -256,10 +256,11 @@ float fz_atof(const char *s) * as we convert to a float. */ errno = 0; d = strtod(s, NULL); - if (errno == ERANGE || d > FLT_MAX || d < -FLT_MAX) { + if (errno == ERANGE || isnan(d)) { /* Return 1.0, as it's a small known value that won't cause a - * divide by 0. */ + divide by 0. */ return 1.0; } + d = CLAMP(d, -FLT_MAX, FLT_MAX); return (float)d; } -- cgit v1.2.3 From b75dd982f18ce02781ce2a36e630860153f96ec9 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Thu, 23 Feb 2012 02:19:12 +0100 Subject: Test both coordinates when checking for empty/infinite rect and bboxes. --- fitz/fitz.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'fitz') diff --git a/fitz/fitz.h b/fitz/fitz.h index d80204f0..6427537f 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -545,7 +545,7 @@ extern const fz_bbox fz_infinite_bbox; An empty rectangle is defined as one whose area is zero. */ -#define fz_is_empty_rect(r) ((r).x0 == (r).x1) +#define fz_is_empty_rect(r) ((r).x0 == (r).x1 || (r).y0 == (r).y1) /* fz_is_empty_bbox: Check if bounding box is empty. @@ -553,7 +553,7 @@ extern const fz_bbox fz_infinite_bbox; Same definition of empty bounding boxes as for empty rectangles. See fz_is_empty_rect. */ -#define fz_is_empty_bbox(b) ((b).x0 == (b).x1) +#define fz_is_empty_bbox(b) ((b).x0 == (b).x1 || (b).y0 == (b).y1) /* fz_is_infinite: Check if rectangle is infinite. @@ -561,7 +561,7 @@ extern const fz_bbox fz_infinite_bbox; An infinite rectangle is defined as one where either of the two relationships between corner coordinates are not true. */ -#define fz_is_infinite_rect(r) ((r).x0 > (r).x1) +#define fz_is_infinite_rect(r) ((r).x0 > (r).x1 || (r).y0 > (r).y1) /* fz_is_infinite_bbox: Check if bounding box is infinite. @@ -569,7 +569,7 @@ extern const fz_bbox fz_infinite_bbox; Same definition of infinite bounding boxes as for infinite rectangles. See fz_is_infinite_rect. */ -#define fz_is_infinite_bbox(b) ((b).x0 > (b).x1) +#define fz_is_infinite_bbox(b) ((b).x0 > (b).x1 || (b).y0 > (b).y1) /* fz_matrix is a a row-major 3x3 matrix used for representing -- cgit v1.2.3