summaryrefslogtreecommitdiff
path: root/fitz/base_geometry.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-01-06 14:42:25 +0000
committerRobin Watts <robin.watts@artifex.com>2012-01-06 14:45:38 +0000
commit6dd9108c5865c1ea2ab0e834f4ae85aa279bcca9 (patch)
treefe3d0a01115cf56f5e9d74c1810094ee2bd8338c /fitz/base_geometry.c
parente504b09e060020c6e7d3478f617a24528de4116d (diff)
downloadmupdf-6dd9108c5865c1ea2ab0e834f4ae85aa279bcca9.tar.xz
Various fixes to avoid arithmetic problems.
Various fixes to avoid overflow problems, division by zeros, use of uninitialised variables etc. All from/suggested by Zenikos patch.
Diffstat (limited to 'fitz/base_geometry.c')
-rw-r--r--fitz/base_geometry.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/fitz/base_geometry.c b/fitz/base_geometry.c
index 00a85c9b..4f9ef8b6 100644
--- a/fitz/base_geometry.c
+++ b/fitz/base_geometry.c
@@ -153,10 +153,16 @@ fz_bbox
fz_round_rect(fz_rect f)
{
fz_bbox i;
- i.x0 = floorf(f.x0 + 0.001f); /* adjust by 0.001 to compensate for precision errors */
- i.y0 = floorf(f.y0 + 0.001f);
- i.x1 = ceilf(f.x1 - 0.001f);
- i.y1 = ceilf(f.y1 - 0.001f);
+ /* adjust by 0.001 to compensate for precision errors */
+ f.x0 = floorf(f.x0 + 0.001f);
+ f.y0 = floorf(f.y0 + 0.001f);
+ f.x1 = ceilf(f.x1 - 0.001f);
+ f.y1 = ceilf(f.y1 - 0.001f);
+#define SAFE_INT(f) ((f > INT_MAX) ? INT_MAX : ((f < INT_MIN) ? INT_MIN : (int)f))
+ i.x0 = SAFE_INT(f.x0);
+ i.y0 = SAFE_INT(f.y0);
+ i.x1 = SAFE_INT(f.x1);
+ i.y1 = SAFE_INT(f.y1);
return i;
}