[dia] Bug 710818 - Overflow safe wrappers for acos/asin (now really)



commit 9a1f90855fb65ae1f129ccf5687bdf5ad3a37a55
Author: Hans Breuer <hans breuer org>
Date:   Fri Mar 14 19:53:35 2014 +0100

    Bug 710818 - Overflow safe wrappers for acos/asin (now really)
    
    acos() and asin() are only defined in a certain range. Implement some
    range/overflow safe wrappers rather than potentially passing infinite
    to other modules (e.g. cairo did assert() on it.)
    
    Additionally check for !isinf() in cairo plug-in (should not trigger
    anymore).

 lib/geometry.c                     |   16 +++++++---------
 plug-ins/cairo/diacairo-renderer.c |    2 ++
 2 files changed, 9 insertions(+), 9 deletions(-)
---
diff --git a/lib/geometry.c b/lib/geometry.c
index a67427a..004ef38 100644
--- a/lib/geometry.c
+++ b/lib/geometry.c
@@ -832,13 +832,12 @@ dia_matrix_is_invertible (const DiaMatrix *matrix)
 real
 dia_asin (real x)
 {
-  real r = asin (x);
   /* clamp to valid range */
-  if (r < -M_PI/2)
+  if (x <= -1.0)
     return -M_PI/2;
-  else if (r > M_PI/2)
+  if (x >= 1.0)
     return M_PI/2;
-  return r;
+  return asin (x);
 }
 
 /*!
@@ -847,11 +846,10 @@ dia_asin (real x)
 real
 dia_acos (real x)
 {
-  real r = acos (x);
   /* clamp to valid range */
-  if (r < 0)
-    return 0;
-  else if (r > M_PI)
+  if (x <= -1.0)
     return M_PI;
-  return r;
+  if (x >= 1.0)
+    return 0.0;
+  return acos (x);
 }
diff --git a/plug-ins/cairo/diacairo-renderer.c b/plug-ins/cairo/diacairo-renderer.c
index c9a0bc6..238e157 100644
--- a/plug-ins/cairo/diacairo-renderer.c
+++ b/plug-ins/cairo/diacairo-renderer.c
@@ -706,6 +706,8 @@ draw_arc(DiaRenderer *self,
   DIAG_NOTE(g_message("draw_arc %fx%f <%f,<%f", 
             width, height, angle1, angle2));
 
+  g_return_if_fail (!isnan (angle1) && !isnan (angle2));
+
   cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
 
   if (!renderer->stroke_pending)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]