[gdk-pixbuf] pixops: Be smarter than gcc's optimizer



commit dd4b061c27dc0865c8f8987d294de6e04b321c18
Author: Benjamin Otte <otte redhat com>
Date:   Sat Aug 22 23:06:23 2015 +0200

    pixops: Be smarter than gcc's optimizer
    
    gcc realizes that the overflow checks aren't necessary. Why not?
    
    Well, if an int overflows, the behavior is undefined. And turning on
    -fomit-instructions is valid behavior in an undefined situation.

 gdk-pixbuf/pixops/pixops.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/gdk-pixbuf/pixops/pixops.c b/gdk-pixbuf/pixops/pixops.c
index b7951c7..5564a40 100644
--- a/gdk-pixbuf/pixops/pixops.c
+++ b/gdk-pixbuf/pixops/pixops.c
@@ -1272,18 +1272,17 @@ make_filter_table (PixopsFilter *filter)
   int i_offset, j_offset;
   int n_x = filter->x.n;
   int n_y = filter->y.n;
-  int n_weights;
   int *weights;
 
-  n_weights = SUBSAMPLE * SUBSAMPLE * n_x;
-  if (n_weights / (SUBSAMPLE * SUBSAMPLE) != n_x)
-    return NULL; /* overflow, bail */
+  /* check n_x doesn't overflow */
+  if (G_MAXINT / (SUBSAMPLE * SUBSAMPLE) < n_x)
+    return NULL;
 
-  n_weights *= n_y;
-  if (n_weights / (SUBSAMPLE * SUBSAMPLE * n_x) != n_y)
-    return NULL; /* overflow, bail */
+  /* check n_y doesn't overflow */
+  if (G_MAXINT / (SUBSAMPLE * SUBSAMPLE * n_x) < n_y)
+    return NULL;
 
-  weights = g_try_new (int, n_weights);
+  weights = g_try_new (int, SUBSAMPLE * SUBSAMPLE * n_x * n_y);
   if (!weights)
     return NULL; /* overflow, bail */
 


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