From dd4b061c27dc0865c8f8987d294de6e04b321c18 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 22 Aug 2015 23:06:23 +0200 Subject: [PATCH 2/2] 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 file 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 */ -- 2.5.2