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



commit 67000b5a9ae05756f3f32655eaf8759818c4693c
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).
    
    (cherry picked from commit 9a1f90855fb65ae1f129ccf5687bdf5ad3a37a55)
    
    Conflicts:
        plug-ins/cairo/diacairo-renderer.c

 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 598e86b..91e5096 100644
--- a/lib/geometry.c
+++ b/lib/geometry.c
@@ -793,13 +793,12 @@ calculate_object_edge(Point *objmid, Point *end, DiaObject *obj)
 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);
 }
 
 /*!
@@ -808,11 +807,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 079446e..5839deb 100644
--- a/plug-ins/cairo/diacairo-renderer.c
+++ b/plug-ins/cairo/diacairo-renderer.c
@@ -513,6 +513,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, 1.0);
 
   /* Dia and Cairo don't agree on arc definitions, so it needs


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