summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/pixops
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-08-22 23:06:23 +0200
committerBenjamin Otte <otte@redhat.com>2015-08-22 23:06:23 +0200
commitdd4b061c27dc0865c8f8987d294de6e04b321c18 (patch)
tree7d8286675e87e7158bdb530052f263dd8a956678 /gdk-pixbuf/pixops
parent3df91dc6c6f8d1421e9c8756959280de792af77a (diff)
downloadgdk-pixbuf-dd4b061c27dc0865c8f8987d294de6e04b321c18.tar.gz
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.
Diffstat (limited to 'gdk-pixbuf/pixops')
-rw-r--r--gdk-pixbuf/pixops/pixops.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/gdk-pixbuf/pixops/pixops.c b/gdk-pixbuf/pixops/pixops.c
index b7951c721..5564a4009 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 */