summaryrefslogtreecommitdiff
path: root/src/cairo-matrix.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2007-07-05 18:52:21 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2007-07-05 19:15:07 +0100
commit35ef8419a981929b65157407485ec001b69b3391 (patch)
treef4f0ec173d20f4051dd97e1ee492aa862e1c5aea /src/cairo-matrix.c
parent7eaba5d5fbf83f66b39db42a89db3e7a892c2ea0 (diff)
downloadcairo-35ef8419a981929b65157407485ec001b69b3391.tar.gz
[cairo-matrix] Check determinant for invalid numbers.
By checking matrices for invalid determinants, we can prevent the setting and application of invalid matrices. The trick used here is that NaNs, as specified by IEE754, always return FALSE in comparisons. Since we know that the square of the determinant must be positive definite, then if the comparison is FALSE the computation must have resulted in a NaN.
Diffstat (limited to 'src/cairo-matrix.c')
-rw-r--r--src/cairo-matrix.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/cairo-matrix.c b/src/cairo-matrix.c
index c85b02768..9e51d04c5 100644
--- a/src/cairo-matrix.c
+++ b/src/cairo-matrix.c
@@ -475,6 +475,10 @@ cairo_matrix_invert (cairo_matrix_t *matrix)
if (det == 0)
return CAIRO_STATUS_INVALID_MATRIX;
+ /* this weird construct is for detecting NaNs */
+ if (! (det * det > 0.))
+ return CAIRO_STATUS_INVALID_MATRIX;
+
_cairo_matrix_compute_adjoint (matrix);
_cairo_matrix_scalar_multiply (matrix, 1 / det);