[pango/pango2-color-palette: 38/71] Be careful with acos




commit 310f8269686b36a4bcc95560246a39e0ecfe4be5
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jun 23 09:49:20 2022 -0400

    Be careful with acos
    
    If the input is outside the [0, 1] range,
    acos returns NaN, so clamp to be safe.

 pango/pango-matrix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/pango/pango-matrix.c b/pango/pango-matrix.c
index 78aacae6d..3f263101d 100644
--- a/pango/pango-matrix.c
+++ b/pango/pango-matrix.c
@@ -269,7 +269,7 @@ pango_matrix_get_rotation (const PangoMatrix *matrix)
 
   pango_matrix_transform_distance (matrix, &x, &y);
 
-  return RAD_TO_DEG (acos (x /  sqrtf (x*x + y*y)));
+  return RAD_TO_DEG (acos (CLAMP (x /  sqrtf (x*x + y*y), -1., 1.)));
 }
 
 /**


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